I would like certain rows in an Ultragrid to be disabled depending on a boolean Sync property in the row. I have thought of two different solutions but neither have worked out.
1) Databind the Sync property to the Activation property of the row. Is this possible?
2) In an event such as the InitializeRow event of the grid find out what the Sync property is and disable the row if it is set to true. This method works apart from if some more rows are then added to the grid and the grid is then saved, the data reorders itself so that the disabled row isn't containing the right data. Therefore I need a way of knowing when this happens so that I can go through and disable the right rows again afterwards.
private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
{
e.Row.Activation = Infragistics.Win.UltraWinGrid.Activation.AllowEdit;
if (e.Row.Cells[grdBoundGrip.DisplayLayout.Bands[0].Columns["Sync"]].Value != null && (bool)e.Row.Cells[grdBoundGrip.DisplayLayout.Bands[0].Columns["Sync"]].Value)
e.Row.Activation = Infragistics.Win.UltraWinGrid.Activation.Disabled;
}
You can also write it in your own function. I hope below solution might help you.
Create a windows form "test".. and drag/drop an "ultragird" in that windows form as shown below..
create a form load function "test_Load".. and try below code.. your rows with sync "false" is disabled..
private void test_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Address", typeof(string));
dt.Columns.Add("Sync", typeof(string));
dt.Rows.Add(new object[] {"John","United States","False" });
dt.Rows.Add(new object[] { "Xing", "China", "True" });
dt.Rows.Add(new object[] { "Ram", "Nepal", "True" });
dt.Rows.Add(new object[] { "Germany", "Thomas", "False" });
dt.Rows.Add(new object[] { "Pedrik", "Russia", "True" });
ultraGrid1.DataSource = dt;
ultraGrid1.DataBind();
DisableRowsWithSyncOff(dt.Rows.Count);
}
private void DisableRowsWithSyncOff(int _rowcount)
{
for (int i = 0; i < _rowcount; i++)
{
if (!Convert.ToBoolean(ultraGrid1.Rows[i].Cells["Sync"].Value.ToString()))
{
ultraGrid1.Rows[i].Activation = Infragistics.Win.UltraWinGrid.Activation.Disabled;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With