3
votes

My setup:

C#.Net 4.0, Windows Forms, DevExpress 13.1.5 although I doubt its a DX issue

I have a form with a GridControl (with GridView) on the top and a detail area that holds TextEdits and other edits in a LayoutControl below. Both the grid and the edits below are bound to the properties of the objects contained in a list in the binding source. The grid is set to ReadOnly, MultiSelect, RowSelect and all its columns are set to ReadOnly, not focusable. Editing is only happening in the detail area below.

The behavior I want to create:

When multiple rows are selected in the grid the edits below should show the following:

  • the value of field in question is the same in all selected rows -> show the value
  • the value of the field in question differs between the rows -> show nothing

if the user writes into the TextEdit while multiple rows are selected:

  • the value of the edit should update the values of the same field of all the selected rows

Where I am with this:

I'm working on a solution by building a custom BindingSource that would be aware of the selection. It would bind the list of object to the grid and a single object that is not part of the list to the edits. Depending on the selection I would set the properties of that single object or forward its changes to the selected objects in the list.

I got that working for a single property with 2 binding sources and would now extend it to use reflection to do this for all of the public properties. I also want to encapsulate the whole behavior into a class that looks and acts like BindingSource just with that added behavior.

The question:

Is there a simpler way to achieve this? Does something already exist which can do this that I overlooked in either .Net or DevExpress? Are there traps to my approach that I should consider or why I should go about this totally differently?

1
Interesting question, maybe you should ask this one at devexpress support, it would be more likely you get what your are looking for. devexpress.com/Support/Center/Question/Create - luis_laurent

1 Answers

2
votes

I think that you can achieve your goal in a simpler manner:

Just bind a single BindingSource with all the data that you need to your grid. That should display the data.

Then, bind the required fields from that same BS do the edits through the DataBindings propriety.

You can then implement a save object (through a control or programatically) so the changes made in the edits are shown in the grid.

To check the grid values, you can use:

//get the handles of the rows
gridView.GetSelectedRows();

//get the value of the desirable cells
gridView.GetRowCellValue(handle, column);

Also, in future projects, consider using the Entity Framework to construct a data-aware model and custom objects based on the elements of your Database.

Hope this helped!