Hi,
One of my grid columns having checkboxes and header checkbox allowing check/uncheck all.
For some reason when I am checking single checkbox in grid row header checkbox changing state to Indeterminate as well, anyway to prevent this?
I have following settings on this column:
Me.grd.DisplayLayout.Bands(0).Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBoxMe.grd.DisplayLayout.Bands(0).Header.CheckBoxSynchronization = HeaderCheckBoxSynchronization.RowsCollectionMe.grd.DisplayLayout.Bands(0).Header.CheckBoxVisibility = HeaderCheckBoxVisibility.Always
Thanks!
Hello,
When the HeaderCheckBoxSynchronization is set to Band or RowsCollection, the Cell values and header checkbox will always be kept synchronized. Therefore, changing the value of one of the affected cells, will change its header checkbox.
To achieve the desired results, you'll have to handle the synchronization yourself.
First you'll have to change the CheckBoxSynchronization of the appropriate column to HeaderCheckBoxSynchronization.None.
Me.grd.DisplayLayout.Bands(0).Columns(0).Header.CheckBoxSynchronization = HeaderCheckBoxSynchronization.None
Now you'll need to make sure the values of the cells are changed whenever the checkbox is clicked. This can be done by handling the AfterHeaderCheckStateChanged event, and setting the value for each row in e.Rows.
Private Sub grd_AfterHeaderCheckStateChanged(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.AfterHeaderCheckStateChangedEventArgs) Handles grd.AfterHeaderCheckStateChanged Dim column As UltraGridColumn = e.Column Dim rows As RowsCollection = e.Rows Dim checkStateValue = column.GetHeaderCheckedState(rows) For Each row In rows row.Cells(column).Value = checkStateValue Next End Sub
This should help you achieve your desired functionality. Let me know if I can be of further assistance.
Thanks,
Chris
Hi Chris,
I followed your code and its working fine.. but the problem i am facing is when i check the header to true , all the rows are checked and vice versa.. but once i check the header true and manually uncheck any of the rows, it wont change the header to uncheck,
Please help me ... thanks in advance
Since you've turned off the automatic synchronization in order to produce your own customized synchronization, you will need to handle synchronizing the header checkbox to match the cell values.
Assuming you want the header checkbox to be unchecked (except when all cell in the column are checked), you will want to code similar to the following in the CellChanged or AfterCellUpdate event handler:
Private Sub grd_CellChange(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles grd.CellChange Dim originalInCellChange = Me.inCellChange Me.inCellChange = True Try Dim cell As UltraGridCell = e.Cell Dim column As UltraGridColumn = cell.Column Dim rows As RowsCollection = cell.Row.ParentCollection Dim newCellValue As Boolean = cell.EditorResolved.Value Dim currentHeaderCheckState As CheckState = column.GetHeaderCheckedState(rows) If newCellValue Then If Not (currentHeaderCheckState = CheckState.Checked) Then ' the header is not checked but the new cell value is true ' so we need to loop through all the rows (assuming that we want to synchronize based on the rows collection) ' to determine if we need to check the header Dim shouldCheckHeader As Boolean = True For Each row In rows Dim cellInRow = row.Cells(column) If cell IsNot cellInRow AndAlso cellInRow.Value = False Then shouldCheckHeader = False Exit For End If Next If (shouldCheckHeader) Then column.SetHeaderCheckedState(rows, True) End If End If ElseIf currentHeaderCheckState = CheckState.Checked Then ' the header is checked but the new cell value is false, ' so turn off the header column.SetHeaderCheckedState(rows, False) End If Finally Me.inCellChange = originalInCellChange End Try End Sub
Additionally, you will want to add a recursion flag at the start of the AfterHeaderCheckStateChanged event handler, to prevent the SetHeaderCheckedState() in CellChanged from triggering all the cell to be set to False/Unchecked.
If (Me.inCellChange) Then Return End If
Let me know if you require any further assistance with this.
For first click on header checkbox it is not working.