Hello,
I would like to add check boxes column to my grid. The list that I pull for the database does not contain boolean column, I would like to add it on the fly. Here is the code from my testing project where I am trying to achieve this:
using Infragistics.Win.UltraWinGrid; using System; using System.Collections.Generic; using System.Windows.Forms; namespace UITests { public partial class Form1 : Form { const string IsChecked = "IsChecked"; public Form1() { InitializeComponent(); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); var isChecked = ultraGrid1.DisplayLayout.Bands[0] .Columns.Add(IsChecked, string.Empty); isChecked.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox; isChecked.Header.CheckBoxVisibility = HeaderCheckBoxVisibility.Always; isChecked.DefaultCellValue = Infragistics.Win.DefaultableBoolean.False; ultraGrid1.DataSource = Data; } private List<TestItem> Data { get { var data = new List<TestItem>(); for (var i = 0; i < 3; ++i) { data.Add(new TestItem() { ID = i.ToString(), Name = "name" + i, Description = "description" + i }); } return data; } } } public class TestItem { public string ID { get; set; } public string Name { get; set; } public string Description { get; set; } } }
I want all row and header checkboxes to be unchecked by default, but they are in an indeterminate state:
Hello Dev,
I have put together a sample project based on the code that you have provided, and it appears that the reason that the checkboxes are in an indeterminate state is because there is no associated DataType with the column that you have added, and so that data type will default to String, which does not convert to a definite checkbox value initially.
If you set the DataType property of your column to typeof(bool), this will default the checkboxes to all be unchecked at the start.
Please let me know if you have any other questions or concerns on this matter.
Also... it's not really important, but if you set the DataType of the column to Bool, setting the Style on the column is unnecessary, since it will default to CheckBoxes for a bool column.