Hello,
I have two questions about using the UltraGrids with a BindingSource.
Firstly, why is the first row automatically made active after binding the bindingsource as the grid's datasource? I don't like this functionality, because strangely enough the Position- or CurrentChanged is not called when this row is automatically selected.
This causes the CurrentChanged event not to be fired when a user actually clicks (and selects/makes active) that first row. In order to get around this issue, I have bound the AfterRowActivate event and I unbind it the first time it has fired. In the event code I check whether the Position of the BindingSource = 0 and if it is, I fire the CurrentChanged event myself.
This is really annoying; is there any other way around this? I would like it i the first row doesn't become active automatically, but the CurrentChanged event would still be fired if the first row is made active.
Secondly, why doesn't the UltraGrid have a DataSourceChanged event or something like that? I really need it, but I can't find anything in the API.
Davio said:Firstly, why is the first row automatically made active after binding the bindingsource as the grid's datasource? I don't like this functionality, because strangely enough the Position- or CurrentChanged is not called when this row is automatically selected.
The CurrencyManager in DotNet does this, it's nothing to do with the grid. The grid responds to this by synchronizing it's ActiveRow with the current position of the CurrencyManager, though. You can turn this off, if you like, by setting SyncWithCurrencyManager on the grid to false.
Davio said:Secondly, why doesn't the UltraGrid have a DataSourceChanged event or something like that? I really need it, but I can't find anything in the API.
Events are typically used by the developer to detect user actions which you would not otherwise be able to detect. Since the user cannot set the DataSource on the grid, the only way the DataSource can be changed is if you change it in code. And since you know you did so, you don't need an event to tell you that this happened. I recommend adding a method somewhere and always setting the DataSource on the grid through that method. That way, you can always trap when a change occurs.
Thanks for your answer, I'll try to see how I can incorporate that for my code. It's just really awkward that the CurrencyManager automatically selects the first position, maybe there's a property to negate that (would like to keep the Sync).
I am binding the datasource in a special method, maybe I need to extend it and pass it an extra parameter for my specific case.
Davio said:Thanks for your answer, I'll try to see how I can incorporate that for my code. It's just really awkward that the CurrencyManager automatically selects the first position, maybe there's a property to negate that (would like to keep the Sync).
If there is such a setting, I'm not aware of it. But that doesn't mean it doesn't exist.
Mike,
I am working with a multi-band grid, the CurrentChanged event on CurrencyManger getting fired only when I select the different parent band row, for example there are two groups (G1 and G2) and G1 has P1, P2 and P3 Products, and G2 has P4, P5 products. that is GroupList is band 1, ProductList is band 2.
Now let us say I selected P1, and then P2, CurrentChanged won't fire, but if I select either G2 or P4 or P5 i.e any row under the top band rows the CurrentChanged will fire.
How to fire the CurrentChanged on CurrencyManager even upon selecting P1, P2 or P3 i.e within the same parent group.
Hi,
There is no one CurrencyManager that manages the current row at every level in the hierarchy. So you will have to get the CurrencyManager for each level of data. I have attached a small sample project here which demonstrates this.
EDIT:
The forums seem to be having a problem and I cannot attach a file right now. But I just bound a grid to a data source with two bands ("Band 0" and "Band 1") and here's the code:
private void Form1_Load(object sender, EventArgs e) { CurrencyManager rootCM = (CurrencyManager)this.ultraGrid1.BindingContext[this.ultraDataSource1, "Band 0"]; rootCM.PositionChanged += new EventHandler(rootCM_PositionChanged); CurrencyManager childCM = (CurrencyManager)this.ultraGrid1.BindingContext[this.ultraDataSource1, "Band 0.Band 1"]; childCM.PositionChanged += new EventHandler(childCM_PositionChanged); } void rootCM_PositionChanged(object sender, EventArgs e) { CurrencyManager cm = (CurrencyManager)sender; Debug.WriteLine(cm.Position, "Root Position Changed"); } void childCM_PositionChanged(object sender, EventArgs e) { CurrencyManager cm = (CurrencyManager)sender; Debug.WriteLine(cm.Position, "Child Position Changed"); }
My eventual workaround was just using the AfterRowActivate of the Grid and manually firing CurrentChanged on the bindingSource if the ActiveRow:Index is different from the current bindingSource:Position. This still doesn't work for the first row, so I check for that manually.
Thanks Mike..