Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading field info from datagrid record

Status
Not open for further replies.

johnkoutstaal

Programmer
Aug 8, 2006
10
NL
Dear vb .net users,

Being programming in Vb .net we are busy to get information from a datagrid that's get's the information from a dataset (msAccess database).

With the script:
Label1.Text = datagridPeople.CurrentRowIndex()
we can find the record that's selected by the event mouse-up.

How can we get the field value (for example "name") from this selected record?

Hope you can give information.

Regards,
John.
 
John,


myval = DataGrid1.Item(DataGrid1.CurrentRowIndex, 2)

2 is the column number of the grid change it to what you want.

--or

(orig From dougP)
Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Click

Dim currRow As DataRow
Dim myColumn As DataColumn
Dim dataGridTable As DataTable
dataGridTable = CType(DataGrid1.DataSource, DataTable)
' Set the current row using the RowNumber property of the CurrentCell.
currRow = dataGridTable.Rows(DataGrid1.CurrentRowIndex)
myColumn = dataGridTable.Columns(0) 'column number 0 is fisrt column
' Get the value of the column 1 in the DataTable.
textbox1.Text = currRow(myColumn, DataRowVersion.Current).ToString()
End Sub



-- or


text1.text= Me.DataGrid1.CurrentCell





good luck

 
Hi Dashley,

Thanks a lot for the given information!! It is working as I wanted

John.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top