Tuesday, May 28, 2013

Checkbox in UltraGrid (Check Cell)

Cells[Check] data type is bool. You didn't need any code to make checkbox in Ultragrid. Just use datasource with datatype bool, and it will become Checkbox.

Code for check the checkbox when clicked:
private void DG_ClickCell(object sender, ClickCellEventArgs e)
        {
            Infragistics.Win.UltraWinGrid.UltraGrid grid = (UltraGrid)sender;
            Infragistics.Win.UIElement element = grid.DisplayLayout.UIElement.LastElementEntered;

            if (element is Infragistics.Win.UIElement)
            {
                UltraGridCell cell =
                element.GetContext(typeof(UltraGridCell)) as UltraGridCell;
                if (cell != null)
                {
                    //cell.Value = !((bool)cell.Value);
                    //e.Cell.Row.Cells["Check"].Value = cell.Value;
                    e.Cell.Row.Cells["Check"].Value = !((bool)e.Cell.Row.Cells["Check"].Value);
                }
            }
        }

Code for make a "check all" in header:

Copy and paste this code in UltraGrid InitializeLayout
ugPostingDegree.DisplayLayout.Bands[0].Columns["Check"].Hidden = false;
ugPostingDegree.DisplayLayout.Bands[0].Columns["Check"].Header.CheckBoxVisibility = Infragistics.Win.UltraWinGrid.HeaderCheckBoxVisibility.Always;
ugPostingDegree.DisplayLayout.Bands[0].Columns["Check"].Header.CheckBoxSynchronization = Infragistics.Win.UltraWinGrid.HeaderCheckBoxSynchronization.Band;
ugPostingDegree.DisplayLayout.Bands[0].Columns["Check"].Header.VisiblePosition = 7;
ugPostingDegree.DisplayLayout.Bands[0].Columns["Check"].Width = 50;
ugPostingDegree.DisplayLayout.Bands[0].Columns["Check"].CellActivation = Infragistics.Win.UltraWinGrid.Activation.ActivateOnly;


1 comment:

  1. What is the version you used.
    I'm using infragistics2 v8.3. It's not support CheckBoxVisibility property.
    What should I do ?

    ReplyDelete