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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid row/column value selection

Status
Not open for further replies.

jadepatel

Technical User
Sep 4, 2002
35
GB
Hi,

I wanted to ask anyone if they have done anything silimar to this...
I have the following code to highlight the entire row when any cell of the datagrid is clicked...

Private Sub DGrid1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DGrid1.MouseUp
'code to select whole line from the datagrid when any cell is clicked
Dim pt = New Point(e.X, e.Y)
Dim hti As DataGrid.HitTestInfo = DGrid1.HitTest(pt)
If hti.Type = DataGrid.HitTestType.Cell Then
DGrid1.CurrentCell = New DataGridCell(hti.Row, hti.Column)
DGrid1.Select(hti.Row)
End If
End Sub


The Datagrid contains the results of a query that is run against my database.
What i wanted to do is when the user highlights a row in the way shown above, i need to retrieve the value that is stored in the first column of that specific row. I then want this value to be put into a variable so that i can use it as a parameter for a delete query.
Is this possible??


I am using VS.NET 2002 and am creating a windows app using VB.NET

Can anyone plz help me to try and solve this problem?
 
jadepatel,

Once the entire row is selected this is the code that I use to get the needed cells from within the datagrid.

dr = dsData.Tables("Info").Rows(dgSchoolList.CurrentRowIndex)

The just use the column names within the datarow to populate your variables or even textboxes on the screen.

Hope this helps,

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top