I have added the following event handler to my tree:
private void treeHierarchy_InitializeDataNode(object sender, InitializeDataNodeEventArgs e)
{
if (e.Node.Cells.Exists("ImageKey"))
e.Node.Cells[
"ImageKey"].Appearance.Image = e.Node.Cells["ImageKey"].Value;
}
The only time the Image property is set is if I set a breakpoint on the IF statement, and examine the Key value (e.Node.Cells[0].Key) in the Immediate window, and then continue execution. Otherwise, the Image property is not set. I'm beginning to believe that Quantum theory applies to large particles :)
Is there another safer way to accomplish this task. I return a ImageKey (integer) from the database which indicates which image to display in the column. I'd like to display the image in the "ImageKey" column, and hide the image key (integer).
What do you think is causing my strange behavior? And, how can I hide the image key (integer)?
In fact, replacing the IF statement with the statement below works just fine?
if (e.Node.Cells.Count > 0)
Hi,
Well, that's clearly not right. What version of the control are you using? Make sure you have the latest service release. This may already be fixed.
If that doesn't help, I recommend that you try to duplicate the issue in a small sample project and submit it so we can check it out. You can either post your sample here or else Submit an incident to Infragistics Developer Support
I modified the code in the "UltraTree Recursive DataBinding" sample to illustrate the problem:
// Make sure that only the highest-level employees show up at// the root level of the tree.if (e.Node.Cells.Exists("SupervisorID")){ if (e.Node.Parent == null && e.Node.Cells["SupervisorID"].Value != DBNull.Value) { e.Node.Visible = false; return; }}
I added the code in BOLD to the Form1.cs InitializeDataNode event handler. Now, if I set a break point inside the IF statement, the breakpoint is never hit.
I tried this out and I was able to duplicate the behavior. It looks like what happens is that the node creates it's cells lazily for efficiency. So the cell does not exist until someone tries to reference it. So it works if you try to actually reference the cell via the indexer (e.Node.Cells["SupervisorID"]), but if you check Exists before that, the cell does not actually exist.
This might be a bug. The Exists method should probably force the creation of the cells, since that's what you would expect to happen. So I'm going to forward this thread over to Infragistics Developer Support so they can look into getting it fixed.
In the mean time, there's a very easy way to work around it. Check for the existance of the column instead of the cell:
if (e.Node.DataColumnSetResolved.Columns.Exists("SupervisorID"))