UltraWinGrid v9.2. The following code borrowed from these forums loops through the columns collection and sets the header check state to checked or unchecked. The problem is this only happens (graphically) on visible (on screen, not hidden) columns, however if you scroll right and view all of the columns, this method then checks or unchecks all columns whether they are visible on screen or not. In other words, after the grid loads for the first time the off screen columns will not receive the visibly checked appearance until you have scrolled and viewed them on screen at least one time and run the method again. The code, however knows that each column is checked regardless of appearing unchecked, so this is a wierd graphics thing. Adding a myGrid.Refresh() and/or myGrid.Update() did not help. Is there a way to have the checked appearance visible without having to first view the columns?
private void myGrid_AfterHeaderCheckStateChanged(object sender, AfterHeaderCheckStateChangedEventArgs e){ UltraGridColumn c = e.Column; CheckState newCheckState = c.GetHeaderCheckedState(e.Rows);
switch (newCheckState) { case CheckState.Checked: foreach (UltraGridColumn siblingColumn in c.Band.Columns) { if (siblingColumn == c) continue;
siblingColumn.SetHeaderCheckedState(e.Rows, true); }
break; case CheckState.Unchecked: foreach (UltraGridColumn siblingColumn in c.Band.Columns) { if (siblingColumn == c) continue;
siblingColumn.SetHeaderCheckedState(e.Rows, false); } break; default: break; }}
I had the similar issue and Here is how I fixed. No action is required from Infragistics but just posting here so that it may help somebody in future.
I was using the Toggle button (separate button outside the grid) to reset the checkbox state of columns of UltraGrid but I also came across the same issue where calling the SetHeaderCheckedState only updated the states of Visible columns.
It would work if I perform either of the following actions before I click the Toggle button.
1. scroll the grid once before clicking the toggle button.
2. or Click toggle button multiple time to, Check, then Uncheck and then Check again. The non-visible columns get checked after doing this.
I tried the sample application given in this post and that also worked on my machine but couldn't find why it doesn't work in my application. There must be some difference in settings of UltraGrid which is different. Anyway, I fixed the issue by adding following code in Form Load event.
foreach (UltraGridColumn col in ultraGrid1.DisplayLayout.Bands[0].Columns) col.SetHeaderCheckedState(ultraGrid1.DisplayLayout.Rows, false);
Great. I'm glad to hear that your problem is resolved. I haven't seen any issues with the Header's Caption returning String.Empty for out of view columns, and I am not able to reproduce the behavior here. If you are still seeing this issue once you finally upgrade, please let us know so we can find the issue.
As far as your note about columns remaining checked when using SetHeaderCheckedState() is concerned, your modifications to the line of code are actually causing the issue. In my sample, the following line of code was used when the newCheckState is Checked or Unchecked:
siblingColumn.SetHeaderCheckedState(e.Rows, (newCheckState == CheckState.Checked));
As such, True is passed as the second parameter to SetHeaderCheckedState() when newCheckState is Checked; and False is passed when newCheckState is Unchecked. As your code most likely splits Checked and UnChecked into different switch cases, it looks like you used the same line of code for Checked, but changed the line of code for UnChecked to:
siblingColumn.SetHeaderCheckedState(e.Rows, (newCheckState == CheckState.Unchecked))
Unfortunately, this means that since newCheckState is Unchecked, you will be passing True to the SetHeaderCheckState() method.
I'm glad I could be of assistance with this issue.
Thanks,
Chris
SOLVED.
Your attached sample works, so I took a hard look at what I am trying to accomplish: To give the user the ability to check / uncheck all columns, but to also allow them to check / uncheck individual columns. The checking of a column places the text or key of the column into a List<string> object.
Things that caused my problems:
Solutions:
Note: Chris - I had to use a bool for siblingColumn.SetHeaderCheckedState(e.Rows, false); instead of siblingColumn.SetHeaderCheckedState(e.Rows, (newCheckState == CheckState.Unchecked)) because the columns would remain checked. Not sure if this is another bug in our 9.2 build?
The working event with comments:
private void gridBuySell_AfterHeaderCheckStateChanged(object sender, AfterHeaderCheckStateChangedEventArgs e){ //Class level flag so this code is not processed while already inside one of the column loops below if (_inProcess) { return; }
UltraGridColumn c = e.Column; CheckState newCheckState = c.GetHeaderCheckedState(e.Rows);
//Need to also check the key because off-screen column captions are emtpy strings if (c.Header.Caption == string.Empty & c.Key == "TCKR") { _inProcess = true; //set the flag switch (newCheckState) { case CheckState.Checked: foreach (UltraGridColumn siblingColumn in c.Band.Columns) { if (siblingColumn == c) continue;
siblingColumn.SetHeaderCheckedState(e.Rows, true); _selPorts.Add(siblingColumn.Key); //add the column's key to the list - the caption may be blank }
siblingColumn.SetHeaderCheckedState(e.Rows, false); } _selPorts.Clear(); //clear the list break; default: break; } _inProcess = false; //reset the flag } else //hit when individual columns are checked / unchecked { switch (newCheckState) { case CheckState.Checked: _selPorts.Add(c.Key); break; case CheckState.Unchecked: _selPorts.Remove(c.Key); break; default: break; } } _selPorts.Sort(); //keep the list sorted}
What behavior does it exhibit when the HeaderCheckBoxSynchronization on the Band's Override is explicitly set to 'None'? I believe one of the fixes in a service release for 9.2 will change the initial starting state of the checkboxes to unchecked, when synchronization is set to None.
I've been trying to reproduce the issue in a sample without success. If you could run and modify the attached sample to reproduce the behavior, it would help me to resolve your issue.
Chris.
I need to proof-read! CORRECTION - First paragraph of my reply should read "The out of view columns do NOT appear to be visually checked, but their checked property is truly checked."