Reputation: 505
I accidentally noticed this mysterious behavior in real app, could not explain why it happened and asking for your help, please.
I confirmed the behavior with very simple sample app.
I created DevExpress blank winforms app. Dropped GridControl and DataNavigator on the form. Then in code I created a DataTable with few rows. Then assigned this table to DataSource of both:
gridControl1.DataSource = table;
dataNavigator1.DataSource = table;
Note, there is no direct relation between gridControl1 and dataNavigator1 and, by idea, DataTable has no of "current row" concept.
Then the "magic" happened: when I click on any control button of the navigator, the movement of focused row reflected in the grid and vice versa - when I click on any row in the grid, focused row is changed and new position is reflected in the navigator.
How gridControl1 and dataNavigator1 know about each other's current position?
By my understanding gridControl1 and dataNavigator1 should not reflect current row position of each other because they have in common only the object (DataTable) that has no "current position" concept. What am I missing here? Thank you.
Here is the code behind the form:
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
private DataTable table;
public Form1()
{
InitializeComponent();
Init();
}
private void Init()
{
table = new DataTable();
table.Columns.Add("col1", typeof(int));
table.Columns.Add("col2", typeof(string));
DataRow row = table.NewRow();
row[0] = 10; row[1] = "first row";
table.Rows.Add(row);
row = table.NewRow();
row[0] = 20; row[1] = "second row";
table.Rows.Add(row);
row = table.NewRow();
row[0] = 30; row[1] = "third row";
table.Rows.Add(row);
gridControl1.DataSource = table;
dataNavigator1.DataSource = table;
}
}
Here are declarations for the grid and navigator in form's designer file:
private DevExpress.XtraEditors.DataNavigator dataNavigator1;
private DevExpress.XtraGrid.GridControl gridControl1;
Upvotes: 0
Views: 130
Reputation: 505
Below is answer from DevExpress support. I learned a lot from it and sharing it in hope that it will be useful for somebody else.
When you assign a data source to a control, the Windows Forms platform itself creates a CurrencyManager object for this data source. If two controls have the same BindingContext and the same data source, the Windows Forms platform will synchronize item selection in these controls. This concept is not specific to DevExpress controls - you can replicate this behavior with two DataGridView controls bound to the same collection.
To avoid this behavior, you need to ensure that aforementioned requirements are not met - either reset the Control.BindingContext property or create a separate BindingSource component for each control.
Upvotes: 0