0

I've just started to use dataGridView, and some things seem strange to me:

  • when there is a Columns property, in which you can add columns, why is there not a Rows property? It seems you can only add rows programmatically. Or am I wrong?
  • the 'star' icon to the left of the first row, can't it be removed?
  • is it possible to disable sorting? I mean when you click on a column, the "sorting-arrow" appears, suggesting that the cells would be sorted.

If it is only possible to add rows programmatically, I have this question:

  • I need a dataGridView with 1 column and x rows. How to do this the quickest and easiest way? The cells will be filled at runtime, programmatically.

update: About disabling sorting, I found out myself: there is a property to change this if you open the (Collections) of the columns.

2
  • Have you reviewed this answer? stackoverflow.com/questions/148854/… Commented Nov 1, 2011 at 10:57
  • String[] dataSource = new String[x]; Bind the array to the DataGridView. Commented Nov 1, 2011 at 10:59

1 Answer 1

4

You can add Rows by calling dataGridView1.Rows.Add();. For multiple rows there is an overload for the same available. dataGridView1.Rows.Add(5);

Now to fill the dataGridView1 rows you can either assign a DataSource and set the DataPropertyName for the Column. Else loop through and fill the data cell wise like dataGridView1[columnindex,rowindex].Value =something

The star icon shows the current row which is being edited, you can choose to hide that cell by setting the RowHeadersVisible to false.

Sign up to request clarification or add additional context in comments.

4 Comments

nice answer and this may help : msdn.microsoft.com/en-us/library/… . first it is better to check msdn and look for "members", each member has already a website like Rows : msdn.microsoft.com/en-us/library/… . enjoy !
Thanks, so I guess it's only possible to add rows programmatically. Ok, I have added 4 rows, each with a different HeaderCell value. When I start the program, the names/values are not totally visible, but I can enlarge the width of that row (I'm just calling it a row although its index is actually -1) manually. Can this be done in code? I've tried various AutoSizeColumnsModes, but it doesn't seem to be doing the trick.
You mean the width of the column? Rows don't have widths. Setting width can definitely be done in code. dataGridView1.Columns[index].Width = value
@harlam357, this would work if the index weren't actually -1. You know, the width of the "column" I need to change is the leftmost column, not the first column with cells beneath.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.