I have an ultragrid with two bands. Band 0 and Band 1. How to loop only through the parent rows i.e only through the band 0 and find the cell value in that band 0 so that I can compare that value ? Am using the InitializeRow Event.
Hi,
If you are using InitializeRow, then you could check the e.Row.Band and look at the Key or the Index of the band to determine if you are dealing with the Band 0 rows.
If you want to loop through the grid rows outside of InitializeRow, then you would do something like this:
foreach (UltraGridRow row in this.ultraGrid1.Rows)
{
if (row.Cells[0].Value == theValueIAmLookingFor)
// do something
}
Yes I want to use the InitializeRow Event.
This is my code:
if( e.Row.Band.Index == 0)
UltraGridBand band = this.ultragrid1.DisplayLayout.Bands[0];
foreach(UltraGridRow row in band.GetEnumerator(GridRowType.DataRow))
if(e.Row.Cells["Key"].Value.Equals("Value am looking for"))
//Do something...
But this loops through all the rows including the child rows. Can i modify this to loop only the parent rows??
This code is very inefficient. The InitializeRow event fires for each row in the grid and may fire multiple times. So it's a bad idea to loop through the rows collection from inside this event. What exactly are you trying to do here that you want to loop?
To answer your question, the Rows collection (grid.Rows) has a GetRowsEnumartor method that lets you specify a particular band and ignores rows in any other bands. But it's still very inefficient (and usually unnecessary) to loop through the row from within the InitializeRow event.
You don't need an event - you can just loop right after you set the grid's DataSource.
I guess you could also use the InitializeLayout event.
Got ur point.
What is the best event to use, to loop through all the band 0 rows after the grid is loaded ?
If you want to add spacing under a row based on that values in that row, then you can use the InitializeRow event. But the event fires for each row. So there's no reason to loop, unless maybe you want to loop through the child rows when the parent row is initialized.
But there's no good reason to loop through the entire rows collection inside InitializeRow, and doing so would be very inefficient.
What I wanted to do is loop through the parent rows and based on the column value in the parent row I would like to insert a row spacing under that band of rows.
Ex:
Date Type
02/23 A //ParentRow
-- Childrows
02/23 B
02/24 A
My output Should be:
Row Space Here