|
-
May 11th, 2006, 07:54 AM
#1
Thread Starter
Junior Member
[02/03] Problem selecting first row in DataGrid
Good morning, all! Here's my problem: I have a normal datagrid that when a user selects a row, it will open up another form w/ details about the selected row. It all works fine except when I click on the very top of the datagrid (where the column names are displayed) - it gives me an error on my next form because current row index = 0. I can add an if to catch this, but then if the first data row is selected, it will not actually select the row. What am I doing wrong?
I would like for the users to click at the top of the datagrid to sort the data and also be able to select the first row in the datagrid. I can't seem to get both functions working properly.
Here's my code:
VB Code:
Private Sub productlist_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Handles productlist.MouseUp
If numclicks > 498 Then
MessageBox.Show("You have selected too many items.")
Else
Try
Dim pt = New Point(e.X, e.Y)
Dim hti As DataGrid.HitTestInfo = productlist.HitTest(pt)
If hti.Type = DataGrid.HitTestType.Cell Then
productlist.CurrentCell = New DataGridCell(hti.Row, hti.Column)
productlist.Select(hti.Row)
ProdID = Me.productlist.Item(Me.productlist.CurrentRowIndex, 0).ToString
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End If
'If productlist.CurrentRowIndex = 0 Then '= "" Then ' Then
'productlist.CurrentRowIndex = 1
'ProdID = ""
'MessageBox.Show("Please select an item inside the grid.")
'Else
Dim myform As New productdetailform
myform.Show()
'End If
End Sub
I can uncomment different parts of the if statement to get different behaviors in the datagrid, but I can not get it to where I can sort by clicking at the top AND select the first row of data.
Thanks for any and all help you folks can provide!
Last edited by amerif; May 12th, 2006 at 07:37 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|