We have a situation where we have a grid that has three bands. If the user checks a box on the second band we do not want the user to be able to add a record to the third band. What would be the best way to accomplish that?
Hello James,
Maybe you could achieve desired behavior using "CheckBoxVisibility" and AllowAddNew properties. Please take a look at the attached sample for more details. If you have any questions, do not hesitate to write us
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace UltraGridWithThreeBandsAddRows { public partial class Form1 : Form { public Form1() { InitializeComponent(); ultraGrid1.DisplayLayout.Bands[0].Columns["A"].Header.CheckBoxVisibility = Infragistics.Win.UltraWinGrid.HeaderCheckBoxVisibility.Always; ultraGrid1.DisplayLayout.Bands[1].Columns["C"].Header.CheckBoxVisibility = Infragistics.Win.UltraWinGrid.HeaderCheckBoxVisibility.Always; ultraGrid1.DisplayLayout.Bands[2].Columns["E"].Header.CheckBoxVisibility = Infragistics.Win.UltraWinGrid.HeaderCheckBoxVisibility.Always; ultraGrid1.DisplayLayout.Bands[0].Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.TemplateOnBottom; ultraGrid1.DisplayLayout.Bands[1].Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.TemplateOnBottom; ultraGrid1.DisplayLayout.Bands[2].Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.TemplateOnBottom; } private void ultraGrid1_BeforeHeaderCheckStateChanged(object sender, Infragistics.Win.UltraWinGrid.BeforeHeaderCheckStateChangedEventArgs e) { switch (e.Column.Key) { case "A": if (e.CurrentCheckState != CheckState.Checked) { ultraGrid1.DisplayLayout.Bands[1].Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.No; ultraGrid1.DisplayLayout.Bands[2].Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.No; } else { ultraGrid1.DisplayLayout.Bands[1].Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.TemplateOnBottom; ultraGrid1.DisplayLayout.Bands[2].Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.TemplateOnBottom; } break; case "C": if (e.CurrentCheckState != CheckState.Checked) { ultraGrid1.DisplayLayout.Bands[2].Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.No; } else { ultraGrid1.DisplayLayout.Bands[2].Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.TemplateOnBottom; } break; case "D": break; } } } }
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace UltraGridWithThreeBandsAddRows
{
public partial class Form1 : Form
public Form1()
InitializeComponent();
ultraGrid1.DisplayLayout.Bands[0].Columns["A"].Header.CheckBoxVisibility = Infragistics.Win.UltraWinGrid.HeaderCheckBoxVisibility.Always;
ultraGrid1.DisplayLayout.Bands[1].Columns["C"].Header.CheckBoxVisibility = Infragistics.Win.UltraWinGrid.HeaderCheckBoxVisibility.Always;
ultraGrid1.DisplayLayout.Bands[2].Columns["E"].Header.CheckBoxVisibility = Infragistics.Win.UltraWinGrid.HeaderCheckBoxVisibility.Always;
ultraGrid1.DisplayLayout.Bands[0].Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.TemplateOnBottom;
ultraGrid1.DisplayLayout.Bands[1].Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.TemplateOnBottom;
ultraGrid1.DisplayLayout.Bands[2].Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.TemplateOnBottom;
}
private void ultraGrid1_BeforeHeaderCheckStateChanged(object sender, Infragistics.Win.UltraWinGrid.BeforeHeaderCheckStateChangedEventArgs e)
switch (e.Column.Key)
case "A":
if (e.CurrentCheckState != CheckState.Checked)
ultraGrid1.DisplayLayout.Bands[1].Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.No;
ultraGrid1.DisplayLayout.Bands[2].Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.No;
else
break;
case "C":
case "D":
Adding rows to the grid is turned off by default. So if your users can add a row to any band in the grid, it's because you explicitly turned this feature on using the AllowAddNew property on the Override.
So you are probably setting something like this:
grid.DisplayLayout.Override.AllowAddNew = AllowAddNew.Yes
There's an Override on the DisplayLayout and also on each Band. So if you set it on the DisplayLayout, you can override that setting on any individual band:
grid.DisplayLayout.Bands[2]..Override.AllowAddNew = AllowAddNew.No