Datgrid problems when refreshing, repopulating

iblanco

New member
Joined
Jul 14, 2003
Messages
2
Hi!

I have a DataGrid Binded to a DataSet in Design time. In this form I select a row in the dataGrid and after pushing a button I go to another form to edit some date related to that row. After updating my information in this new form I call a method from the previous form ( the one with the DataGrid ) called reload().

This is the code for Relaod:


Public Sub Reload()
DsListaClientes1.Clear()
dbaClientes.Fill(DsListaClientes1)
End Sub

dbaClientes is the DataAdapter an DsListaClientes1 the DataSet that popuplates de grid.

The DataGrid seems to repopulate correctly and I can see the changes on it but whatever Cell I choose now its SelectedRowIndex is always 0.

Is this normal? How Can I solve this?

Thanks.
 
Try the following code to see if is still returning row 0

Code:
 Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseDown
        Dim hti As System.Windows.Forms.DataGrid.HitTestInfo
        Dim myGrid As DataGrid = CType(sender, DataGrid)
        hti = myGrid.HitTest(e.X, e.Y)
        Select Case hti.Type
            Case myGrid.HitTestType.Cell
                MsgBox(hti.Row.ToString)
        End Select
    End Sub
 
I took the advice of some other VB experts and changed the DataGrid for a ListView control. At first its a bit strange but after getting used to it works fine.

I dont know very well what you proposed this code for, I already know that it returns 0. I already have a
MsgBox(dtGrid1.CurrentRowIndex) command in the procedure that is executed whenever I change from one cell to another and it returns "normal" values as long as I dont reload the DataGrid. After reloading always returns 0.

Thanks for your reply.
 
Back
Top