I have am having a problem hiding child rows of my self referencing table which are appearing in the root band. I am handling the InitializeRow event and am checking to see if they should be children or root rows. If they are children, I set e.Row.Hidden = true. When running the application no rows are hidden. If I set a break point in the event handler, then the rows will be hidden. This seems very odd to me can anyone give me some pointers on how to make these rows hide properly? I am using 20083.2115.
Sample code below.
-Justin
public Form1() {
InitializeComponent();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
DataColumn dc = null;
DataRow dr = null;
dc = new DataColumn("ID", Type.GetType("System.Int32"));
dt.Columns.Add(dc);
dc = new DataColumn("ParentID", Type.GetType("System.Int32"));
dr = dt.NewRow();
dr["ID"] = 1;
dr["ParentID"] = DBNull.Value;
dt.Rows.Add(dr);
dr["ID"] = 2;
dr["ParentID"] = 1;
dr["ID"] = 3;
dt.TableName = "SelfReferencingTable";
ds.Tables.Add(dt);
ds.Relations.Add(ds.Tables["SelfReferencingTable"].Columns["ID"], ds.Tables["SelfReferencingTable"].Columns["ParentID"]);
this.ultraGrid1.DisplayLayout.MaxBandDepth = 5;
this.ultraGrid1.DataSource = ds;
}
private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e) {
// if i set a break point here, the rows will be hidden correctly
// without a break point or simply running the .exe will not hide any rows
if (e.Row.Band.ParentBand == null) {
if (e.Row.Cells.HasCell("ParentID") && e.Row.Cells["ParentID"].Value != DBNull.Value) {
e.Row.Hidden = true;
Thanks for the reply Mike. I changed my check to see if the column exists to:
e.Row.Band.Columns.Exists("ParentID")
Everything seems to be working correctly now.
This looks okay to me except for the call to HasCell. I don't think you should be checking that. Whether the cell is created or not, you still need to check the value.
If you are concerned about efficiency and don't want to create cells unnecessarily, then use the row.GetCellValue method.
This is discussed in more detail here: WinGrid Performance Guide
I just downloaded the 2009 v.2 WinForm controls, and have verified that the same issue exists there as well.
-Jutin