DataGrid issue

  • Thread starter Thread starter Sebastián::PJ
  • Start date Start date
S

Sebastián::PJ

Hi all.
In VB.Net I used the Item method in order to get a value from a DataGrid.
Now I'm working with C# and I can't use this method.

how the heck do you do that in C#????

TIA,
Sebastián
 
Sebastián,

This is an indexer in C#. You simply have to refer to the row,column of the
cell. I have posted a sample from the MSDN below.

I hope this helps.
----------------------------
//link to the MSDN
http://msdn.microsoft.com/library/d...owsFormsDataGridClassItemTopic.asp?frame=true

private void PrintCellValues(DataGrid myGrid){
int iRow;
int iCol;
DataTable myTable;
// Assumes the DataGrid is bound to a DataTable.
myTable = (DataTable) dataGrid1.DataSource;
for(iRow = 0;iRow < myTable.Rows.Count ;iRow++) {
for(iCol = 0;iCol < myTable.Columns.Count ;iCol++) {
Console.WriteLine(myGrid[iRow, iCol]);
}
}
}
 
If you have specified a DataKeyField in you binding code, then you can do
something like:

int test = Convert.ToInt32(DataGrid1.DataKeys[e.Item.ItemIndex]);
 
Back
Top