How to get cell values out of a selected row in a DataGrid using VB.net?

Apr 1, 2009 at 9:55 PM
I need to know how to get all of the values out of a selected row in a datagrid?  VB.net example would be great!  I would like to loop through each cell in a selected row, grab each value and its corresponding column name, and store both values.  Here is what I have so far... I'm not sure how to access each cell's content.

Dim

dg As DataGrid

 

 

Dim intCounter, intRowIndex, intNumColumns As Integer

 

 

'Retrieves the selected row's Index which is zero based.

 

dg = dgResults

intRowIndex = dg.SelectedIndex

intNumColumns = dgResults.Columns.Count

MessageBox.Show(

"The Row's Number:" & " " & Convert.ToString(intRowIndex) & " " & "The # of Columns" & " " & Convert.ToString(intNumColumns))

 

 

Do While intCounter <= intNumColumns

 

intCounter += 1

 

Loop

 

 
Apr 6, 2009 at 10:38 AM

Hi

i dont know vb.net well, but this is how i get by c#

 private void dataGVReport_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
DataGridRow dgRow = e.Row;
DataRowView rowView = dgRow.Item as DataRowView;

  this rowView contains the current selected row

 }

Apr 6, 2009 at 9:33 PM
Excellent!  Works perfect.  However, I need to use  DataGridRow dgRow = e.Row; and DataRowView rowView = dgRow.Item as DataRowView; in a procedure which is called by a button.  Any ideas?