hi,
I have two UltraGrids side by side, both with Parent and Child (2 hirarcial bands)
i am trying to sync both grids in the aspect of SelectedRow or ActiveRow so when one grid will be clicked the other grid will simply highlight the same row as at the first grid - and vise versa .
if they were both with only one band then it wouldn't be a problem .
ug1.Rows[ug2l.ActiveRow.Index].Activate();
or
ug1.ActiveRow = ug1.Rows[ug2.ActiveRow.Index];
both are same ( I think)
but because they are both with 2 bands i can't find how to sync it at Band wise, however i was able to sync them at the Collapse/Expand events so they both expand and collapse at the same time.
and after reading in the forum i am somewhat confused by SelectedRow VS ActiveRow .
from what i found at the forum is that i should probably focuse on ActiveRow and turn SelectTypeRow to None as i am dealing only with one row at a time.
furthermore, i using the AfterRowActivate event of both grids,
ug1_AfterRowActivate
ug2_AfterRowActivate
a problem that might occure is that when i am using the ug1_AfterRowActivate event to set the ug2 ActiveRow then the ug2_AfterRowActivate will fire and will try to set the ug1 ActiveRow . like some sort of a loop. but i think i know how to resolve that , when i'll be able to resolve my first issue stated above.
Hi,
Are you making the assumption that the grid rows will always be the same? What happens if a user sorts a column in one grid? Or applies filtering to one of the grids?
Assuming that neither of those is enabled, then you would have to find the parent row of the active row first in order to find the matching child row.
private void ultraGrid_AfterRowActivate(object sender, EventArgs e) { UltraGrid grid = (UltraGrid)sender; UltraGrid otherGrid = grid == this.ultraGrid1 ? this.ultraGrid1 : this.ultraGrid2; // Disable this event to prevent recursion grid.EventManager.SetEnabled(GridEventIds.AfterRowActivate, false); otherGrid.EventManager.SetEnabled(GridEventIds.AfterRowActivate, false); try { UltraGridRow activeRow = grid.ActiveRow; if (activeRow == null) { // If there is no activerow, just clear the ActiveRow in the other grid. otherGrid.ActiveRow = null; return; } UltraGridBand band = activeRow.Band; if (band.Index == 0) { // If the active row is in band 0, it's very easy to find. otherGrid.Rows[activeRow.Index].Activate(); return; } // If we reach this code, then the active row is a child row. So first find the // matching parent row. UltraGridRow parentRow = activeRow.ParentRow; UltraGridRow otherParentRow = otherGrid.Rows[parentRow.Index]; // Now that we have the matching parent row, we can activate the // matching child row. otherParentRow.ChildBands[0].Rows[activeRow.Index].Activate(); } finally { // Re-enabole this event. grid.EventManager.SetEnabled(GridEventIds.AfterRowActivate, true); otherGrid.EventManager.SetEnabled(GridEventIds.AfterRowActivate, true); } }
wow , supurb solution, exactly what i was looking for !
minor changes :
1.
UltraGrid otherGrid = grid == this.ultraGrid1 ? this.ultraGrid1 : this.ultraGrid2;is reversed , it should be
UltraGrid otherGrid = grid == this.ultraGrid1 ? this.ultraGrid2 : this.ultraGrid1;
2. and added an if because it was crushing, when the program loads it fires the event by default without me clicking anything, i assume this is when the first row is set to active by default and there is no DataSource set to the "otherGrid" (yet) at that point .
if (band.Index == 0) { // If the active row is in band 0, it's very easy to find.
if (otherGrid.Rows.Count != 0) otherGrid.Rows[activeRow.Index].Activate(); return; }or i could do ultraGrid1.ActiveRow = null; but i'm not sure when. what would be the correct event to add this ? so that the first row will not be ActiveRow by default when loading the program.
also what is the difference between
e.Layout.Override.ActiveAppearancesEnabled = Infragistics.Win.DefaultableBoolean.False;and
ugExcel.DisplayLayout.Override.SelectTypeRow =
SelectType.None;
again, thanks for the wonderful solution !
Checking the rows count here seems reasonable.
I don't understand your question about setting the ActiveRow to null. Why would you want to do that?
sharik said: what is the difference between e.Layout.Override.ActiveAppearancesEnabled = Infragistics.Win.DefaultableBoolean.False;and ugExcel.DisplayLayout.Override.SelectTypeRow = SelectType.None;
what is the difference between
Hm, I hardly know where to start. These are two completely unrelated things. The first line disables the Active appearances. This means that the ActiveCellAppearnce and ActiveRowAppearance defined in the application or through application styling will not be displayed in the grid.
The second line of code turns off selection - so the user cannot select rows in the grid. It has nothing to do with the active row.
Boris, Mike , again thanks for your support, but as i said, i will use 1 grid with Fixed Headers.
thanks