Hi,
I'm hitting a problem trying to initialize rows. In my initialize rows event handler, I look at VisibleHeaders under certain conditions. Basically, I color the row's background yellow, then loop for some number of times turning the cell's background white, starting from the left and moving right.
The problem is that the first IntializeRow event fires, and VisibleHeaders is dirty, and contains no items. This is cause an exception in my code. How can I get around this?
Thanks
Andy
Hi Andy,
If the grid hasn't painted yet, then the VisibleHeaders will not have been created. Have you tried just checking for null?
No, because VisibleHeaders never is null, it's just empty (Count = 0).
I did add a check, but the problem is that my rows have not been properly initialized, because the event doesn't refire unless I tell the grid to do so explicity, and I'm not sure when it would be valid to do so before the painting is done.
So if you just skip it when the Count is 0, you are saying that InitializeRow doesn't fire again for the same row when it paints? Hm... well, you can call grid.Rows.Refresh(FireInitializeRow), but you have a good point about not knowing when to do this. I guess that depends on what you are trying to do and why you are using VisibleHeaders instead of just looking at the Cells collection of the row.
You might also try using GetFirstVisibleColumn on the Band and GetRelatedVisibleColumn on the column to loop through the visible columns as an alternative to VisibleHeaders. I'm not sure if these methods are any different, but I suspect they might work even when VisibleHeaders does not.
Mike Saltzman"]So if you just skip it when the Count is 0, you are saying that InitializeRow doesn't fire again for the same row when it paints?
Exactly. The event is fired once, then the screen displays. I can see it didn't fire again because the cells which should be white are still yellow.
Mike Saltzman"]Hm... well, you can call grid.Rows.Refresh(FireInitializeRow), but you have a good point about not knowing when to do this. I guess that depends on what you are trying to do and why you are using VisibleHeaders instead of just looking at the Cells collection of the row.
I'm trying to create a reverse stepping effect; the grid shows line items. Some items may contain other items; those that contain other items are shown with a yellow background across the entire row. Items which are contained are all yellow, except for the first few cells, which are white. In theory the heirarchy can be arbitralely deep, but in practice I should only have at most three levels.
Mike Saltzman"]You might also try using GetFirstVisibleColumn on the Band and GetRelatedVisibleColumn on the column to loop through the visible columns as an alternative to VisibleHeaders. I'm not sure if these methods are any different, but I suspect they might work even when VisibleHeaders does not.
I did see those methods, but wasn't able to use them because sometimes I need the second or third visible column. I'm trying to do the colors from left to right, on screen, so knowing what order the columns will be displayed in is important.
VisibleHeaders is different, because it's based on the ColScrollRegion, so it's used to place UIElements. It doesn't get created until it's needed, which isn't until after the grid paints. Actually, you could probably force the elements to get created by calling grid.DisplayLayout.VerifyChildElements and then maybe grid.Refresh, but it's probably better and more efficient to use the other methods, which don't rely on UIElements, anyway.
Ok, I didn't see how they fit together at first, but I was able to get this working.
Still, it seems odd though; I can ask for visible columns via these methods, but not get them from the VisibleHeaders collection?
ajj3085 said:I did see those methods, but wasn't able to use them because sometimes I need the second or third visible column. I'm trying to do the colors from left to right, on screen, so knowing what order the columns will be displayed in is important.
Why can't you use these methods to get the first, second, third, fourth, or Xth visible column? These methods should take into account the visible order of the columns on-screen. Hence the word "Visible" in the names of the methods.