[RESOLVED] Manually adding data to DataGridView
I'm using DataGridView without binding it to any source. I want to add all data manually.
I got the way to add a new row.
Code:
empDataGridView.Rows.Add() 'empDataGridView is the name of DataGridView
But, how can I add a piece of data to particular cell of the particular row? And retrieve the Index of row when a row is clicked.
Re: Manually adding data to DataGridView
The row has an Index property that gives you the index of that row in the grid's Rows collection.
If you want to add data to an existing row then you need to index the row's Cells collection to access a particular cell and then set its Value property. If you have all the data before adding then it would be easier to call the overload of Add that has a single Object array parameter. That allows you to pass the cell values and have them added to the cells when the row is created. That parameter is a ParamArray, so you can pass a single Object array or you can pass the discrete values as separate arguments.
Re: Manually adding data to DataGridView
Okay. That wasn't hard actually.
Code:
DataGridView.Rows(index).Cells(index).value
Thanks.