skea
Registered User.
- Local time
- Today, 12:03
- Joined
- Dec 21, 2004
- Messages
- 342
I use this function to select the current record ID in my datagrid. It does it well only when you have used/clicked the Row Header of the datagrid.
When some one clicks from cell to cell, the rows can change too.
I need a function which selects the current Record ID no matter whether the user has clicked in the data grid cell or on the Row Header.
Does any one here have an idea of how this can be done, or how the function below can be used to accomplish this, or has any one used CurrentRowIndex in this situation?
Edits: I realised that one can be able to disable the datagrid cells and do away with the above problem.
The solution to get out of this cave must be better than this, i suppose.
Actually i have found this method hard to deal with, since when the sorting at the column headers is it self not bound to the datasource of the datagrid. It gives me a different value if these column headers are clicked for sorting.
When some one clicks from cell to cell, the rows can change too.
I need a function which selects the current Record ID no matter whether the user has clicked in the data grid cell or on the Row Header.
Does any one here have an idea of how this can be done, or how the function below can be used to accomplish this, or has any one used CurrentRowIndex in this situation?
Code:
Sub ShowRecordID()
Dim myConn As New SqlConnection(strConn)
Dim strSQL As String = "SELECT * FROM tblStudentDetails"
Dim daDetails As New SqlDataAdapter(strSQL, strConn)
Dim dsDetails As New DataSet
myConn.Open()
Dim pt As System.Drawing.Point = Me.dgNewStudents.PointToClient(Cursor.Position)
Dim Hti As DataGrid.HitTestInfo = Me.dgNewStudents.HitTest(pt)
If Hti.Type = DataGrid.HitTestType.RowHeader Then
daDetails.Fill(dsDetails, "tblStudentDetails")
Me.tbStreamID.Text = dsDetails.Tables(0).Rows(Hti.Row).Item("StudentID")
End If
myConn.Close()
End Sub
Edits: I realised that one can be able to disable the datagrid cells and do away with the above problem.
The solution to get out of this cave must be better than this, i suppose.
Actually i have found this method hard to deal with, since when the sorting at the column headers is it self not bound to the datasource of the datagrid. It gives me a different value if these column headers are clicked for sorting.
Last edited: