DataGridView focus jumps to the first column after editing a cell

Answered
0
0

Hei,

I have a problem with the DataGridView. Focus jumps to the first column after editing a cell.

Try attached sample. If i edit something in the “title” cell column it should jump to the “tekst” column after finishing editing the cell. But it jumps to the “name” column.

Wisej 2.1.60

Best regards,

Wilfred

  • You must to post comments
Best Answer
0
0

I think I found the problem. Looks like the Csla framework is firing a MetaDataChanged event every time a field of a child record changes because it’s operating in Xaml mode (WPF). Apparently it needs to reload the list when a single item changes. Wisej uses the WinForms data binding model, if you add this line to Main() it seems to work properly:

Csla.ApplicationContext.PropertyChangedMode = Csla.ApplicationContext.PropertyChangedModes.Windows;

 

  • Wilfred Schønegge
    Hi Luca, Yes works fine now. Had completely forgotten about that setting. Thanks for excellent support here at Wisej as always.
  • You must to post comments
0
0

Thanks for looking into this Luca.

I have expanded the sample to more reflect the real application I’m working on. The user should get the data and then freely move around in the grids to edit data. The user might select “Arthur” edit data for the sons and even edit data for the sons children. Then the user might select “Uther” to edit data for that. Then when everything looks ok the person can click on “save data” to save everything to the database. To make this work we depend on the datasources to control what lines in the grids that have the selection and what data that should be presented in the child + grandchild grid. Everything works as expected except for the problem with the focused cell. In this case for the datasources to work together I don’t think I can use the DataMember property as you suggested.

Best regards,

Wilfred

  • You must to post comments
0
0

I think the issue is where you set the DataMember “Knights”. The DataGridView is bound to a BindingSource instance, not to the data directly (Head) but you set the DataMember of the DataGridView to “Knights”. If you set the DataMember of the headBindingSource to “Knights” then it works fine also using BO.Head.GetHead() since it binds to the Knights list.

Otherwise it’s bound to a list that is a property of the data source and when something changes the changes is seen as a list change instead of an data item change.

  • You must to post comments
0
0

I can reproduce but it doesn’t seem a Wisej issue. I put a break in DataGridView1_CurrentCellChanged and the stack trace shows that the data source is resetting the list when a property changes. Looking at the trace it seems that the data framework thinks that the meta data of the list has changed. It appears that the object Head acts as a list of meta data.

When the data source is changed the grid reloads all the rows and the only information that the data source provides is the current row, there is no current column in the data sources.

I change the code to this and it all works fine:

headBindingSource.DataSource = BO.Head.GetHead().Knights;

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.