Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello


I have a datagrid filled with data and a button to add an empty row

After I pressed the button, I want a record is added to our catalog on the data grid. And focus on that record.


VB
Private Sub Button_Click_2(sender As Object, e As RoutedEventArgs)
    Dim dr As DataRow

    dr = dtGrid.NewRow()
    dr("Status") = 4
    dr("ID") = "0"
    dr("Name") = ""
    dr("CountryId") = "0"
    dtGrid.Rows.Add(dr)

    DG.SelectedItem = dtGrid.Rows.Count - 1
    '' Make the ID field the current column of the grid
    DG.CurrentColumn = DG.Columns(1)
    '' Put the grid into editing mode
    DG.BeginEdit()
    '' Give the grid control focus
    DG.ScrollIntoView(dr)
    DG.BeginEdit()

end sub



How do i get the focus on that record

Thanks
Posted
Comments
Sergey Alexandrovich Kryukov 25-Mar-14 12:45pm    
Selection in a control is not the same as setting of the keyboard focus. Does SelectedItem works for you?
—SA
Christian Amado 1-Apr-14 8:36am    
The same question is here http://www.codeproject.com/Questions/752550/How-Can-I-Place-The-Cell-In-Editmode-Datagrid

1 solution

But i have a question. If i push the button 'Button_Click_2' there will be a row inserted in the datagrid. That is good.

But the cell in column 1 doesn't go in editmode.
What must i do ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900