Enable/Disable selectAll check box in Infragistics UltraWinGrid
-
25-10-2019 - |
Question
I have used Infragistics UltraWinGrid to display data on the Grid. In this grid, there is one check box column. I have added check box in header in this column to selectAll option. Now I want to enable/disable this header check box on any button click event to restrict user to perform any action. Can any one tell me how to do this? Thanks in advance.
Solution
I can think of two options off the top:
1) If you don't want the user to click any of the checkboxes, just hide the entire column if they are not authorized.
2) If you only want to keep the user from selecting all of the items in the grid, add code to the selectAll method to ignore the request if the user is not authorized.
Update
3) If you are using a version of the grid that supports it, you can use:
grid.DisplayLayout.Override.HeaderCheckBoxVisibility = HeaderCheckBoxVisibility.Never
when the form containing the grid is loaded if the user is not authorized.
OTHER TIPS
The check box in the header is provided by a HeaderCheckBoxUIElement and this has an enabled property that can be set to determine if the check box is enabled. To get a reference to the HeaderCheckBoxUIElement you can use the MouseEnterElement and set the Enabled property in that event. For tracking if it is enabled you could use the Tag property of the column.
The code in VB:
Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim col As UltraGridColumn = Me.UltraGrid1.DisplayLayout.Bands(0).Columns("OnSite")
col.Tag = (TypeOf col.Tag Is Boolean AndAlso CBool(col.Tag) = False)
End Sub
Private Sub UltraGrid1_MouseEnterElement(sender As Object, e As Infragistics.Win.UIElementEventArgs) Handles UltraGrid1.MouseEnterElement
If TypeOf e.Element Is HeaderCheckBoxUIElement Then
Dim element As HeaderCheckBoxUIElement = DirectCast(e.Element, HeaderCheckBoxUIElement)
element.Enabled = (TypeOf element.Column.Tag Is Boolean AndAlso CBool(element.Column.Tag) = True)
End If
End Sub
The code in C#:
void ultraGrid1_MouseEnterElement(object sender, UIElementEventArgs e)
{
if (e.Element is HeaderCheckBoxUIElement)
{
HeaderCheckBoxUIElement element = (HeaderCheckBoxUIElement)e.Element;
element.Enabled = (element.Column.Tag is bool && (bool)element.Column.Tag == true);
}
}
private void button1_Click(object sender, EventArgs e)
{
UltraGridColumn col = this.ultraGrid1.DisplayLayout.Bands[0].Columns["OnSite"];
col.Tag = (col.Tag is bool && (bool)col.Tag == false);
}