|
Question : Loop through the cells of a datagrid without knowing the datasource
|
|
Dear Experts,
i need to be able to loop though each cell of a datagrid and output it (somewhere). I need to develop it generically.
If i do not know the datasource of the datagrid, how can this be made possible?
Please help.
|
|
Answer : Loop through the cells of a datagrid without knowing the datasource
|
|
Not sure if this is the best way, but try it:
'get row count Dim iRowCount As Integer = DataGrid1.BindingContext(DataGrid1.DataSource, DataGrid1.DataMember).Count
Dim i As Integer Dim j As Integer
'loop through rows For i = 0 To iRowCount - 1 'start from first column j = 0 Do Try 'output cell content MsgBox(DataGrid1.Item(i, j)) 'try to increase column index j = j + 1 Catch ex As Exception 'if error, asume column index was to hight, go to next row Exit Do End Try Loop Next
|
|
|
|