hi, here i developed code for searching a text from grid row -> childband row
Infragistics.Win.UltraWinGrid.UltraGrid InfraGrid = (Infragistics.Win.UltraWinGrid.UltraGrid)SourceControl; UltraGridRow ChildSelectionRow = null; int test =0; int MainRowIndex, ChildRowIndex; ChildSelectionRow = InfraGrid.Rows[test]; ArrayList ListChk = new ArrayList(); MainRowIndex = Convert.ToInt32(startSearchRow.Split('~')[0]); ChildRowIndex = Convert.ToInt32(startSearchRow.Split('~')[1]); int childcolumn = Convert.ToInt32(columnIndex); int selRowIndex = -1; MainRowIndex--; ChildRowIndex--; childcolumn--; //Getting the list of rows index in an array string[] words = startSearchRow.Split('~'); -> spliting the value like (row)0,childbandrow(0),text foreach (string word in words) { int i = 0; string s = word; if (!int.TryParse(s, out i)) //i now = 108 { MessageBox.Show("Values are modified as string"); return "NULL"; } else { //MessageBox.Show("entered else part"); ListChk.Add(word); } } //Expand the row based on its index for (int i = 0; i < ListChk.Count; i++) { int.TryParse(ListChk[i].ToString(), out test); if (i == 0) { ChildSelectionRow = InfraGrid.Rows[test]; } else { if (i <= ListChk.Count - 1) { if (MainRowIndex >= 0 && ChildRowIndex >= 0 && childcolumn >= 0) { if (InfraGrid.Rows[MainRowIndex].IsExpandable) { InfraGrid.Rows[MainRowIndex].Expanded = true; InfraGrid.Rows[MainRowIndex].Selected = true; if (InfraGrid.Rows[MainRowIndex].ChildBands.Count > 0) { if (InfraGrid.Rows[MainRowIndex].ChildBands[0].Rows.Count > 0 && InfraGrid.Rows[MainRowIndex].ChildBands[0].Rows.Count > ChildRowIndex) { if (InfraGrid.Rows[MainRowIndex].ChildBands[0].Rows[ChildRowIndex].Cells.Count > childcolumn) { if (InfraGrid.Rows[MainRowIndex].ChildBands[0].Rows[ChildRowIndex].Cells[childcolumn].Text == text) { selRowIndex = ChildRowIndex + 1; } else { for (int ii = ChildRowIndex; ii < InfraGrid.Rows[MainRowIndex].ChildBands[0].Rows.Count; ii++) { if (InfraGrid.Rows[MainRowIndex].ChildBands[0].Rows[ii].Cells[childcolumn].Text == text) { selRowIndex = ii + 1; break; } } } } } } } } } } } return "RowIndex :" + selRowIndex;
My Doubt is:
1. i need to iterate childband within childband and need to search the text from childband row.
Thanks
Srinivasan J
Hi Srinivasan,
If I understand you correct, what you want to do is search the root-level row (InfraGrid.Rows[MainRowIndex]) and all of it's descendants in all child bands? Is that right?
If that's what you want, then you are almost there. Your code is currently limited to only the first child band and it's not walking down the chain recursively. So first you have to make sure you include all child bands. And second, you have to walk down the descendants recursively, in case those child bands have child bands of their own.
The first part can be achieved by looping through the ChildBands collection of the row. So instead of just accessing ChildBands[0], you need to loop like this:
foreach (UltraGridChildBand childBand in row.ChildBands) { }
Inside this loop, you can walk down the chain recursively by making use of the enumerators provided by the rows collection. There are methods on the rows collection that give you recursive enumerators for convenience.
UltraGridRow row = this.ultraGrid1.Rows[0]; foreach (UltraGridChildBand childBand in row.ChildBands) { //foreach (UltraGridRow descendantRow in childBand.Rows.GetFilteredInNonGroupByRows) foreach (UltraGridRow descendantRow in childBand.Rows.GetAllNonGroupByRows()) { } }
I put two options inside the loop here, because right now your code does not account for filtering. So your results could end up with an invisible row. So if you want to ignore hidden rows, use GetFilteredInNonGroupByRows instead of GetAllNonGroupByRows.
Using this methods should simplify your code quite a bit.
Also, if you don't want to limit the search to a single root-level row, you could easily loop through every row in the grid like this:
foreach (UltraGridRow row in this.ultraGrid1.Rows.GetFilteredInNonGroupByRows()) { }
Hi Mike Saltzman
I am new to Infragistics technology, I am learning the things day by day, can you elaborate the code for above you explained me. If you explain me with some set of code, it will be more good for my understading.
srinivasan J
I would be happy to write some sample code for you. But in order to do that I want to make sure I understand exactly what you want to do. Can you please explain in more detail?
If I understand correctly, you have a text field of some kind and the user enters some text and maybe presses a button and then you want to search all of the rows in the grid for that text. Is that correct?
Or are you only searching one row and it's descendants?
Which columns are you searching? All of them?
Hi,
I'm just following up on this. Do you still need assistance achieving what you need here?
This seems very similar to your other post which I responded to today, so if this is the same issue, please let me know and I will close one case to avoid confusion.
Hi Mike Saltzman,
Thanks for your reply. yes i need some clarity about searching text from ultragrid expandable childband grid. You given me some code like
foreach(ultragridrow row in ultragird.rows)
{
foreach(ultragridchildband row in row.childband)
}
i cannot understand clearly, because i am very new to this infragistics technology. if you will explain me with sample it will be very help full for me.
in your example,
1. if there will be ultragird with two or three childband's it's good.
2. my question is, (for example, ultragrid has 3 childband, i need to get the 3rd childband -> 2nd row of childband and return the 2nd row of 1st cell text)
i hope this explanation will be enough for your understanding.