Hello.
I have an UltraGrid that loads from an Excel file.
What I would like to do is loop each row and column, the ones that are selected, so that I can get the value and "Header".
For example, for the image I would get the following:
For the first row.
SUB: 431/
P1: 88.2
P2: 96.9
P3: 0
P4: 6.24
P5: 6.86
P6: 209.65
P7: 230.7
P8: 253.8
P9: 97
P10: 0
P11: 88.2
P12: 96.9
P15: 74.97
P16: 76.03397052
For the second row, I will get the values from the SUB: 437/
Can someone please tell me how to achieve this?
Thanks
Hi William,
foreach (UltraGridRow row in this.ultraGrid1.Rows) { foreach (UltraGridCell cell in row.Cells) { Debug.WriteLine(cell.Value.ToString(), cell.Column.Key); } }
Great it worked, I just need to loop through each of the rows that are only selected, the checkbox is a boolean. I tried the following:
if (Convert.ToBoolean(grdPart.ActiveRow.Cells["Seleccionar"].Value) == true) { foreach (UltraGridRow row in this.grdPart.Rows) { foreach (UltraGridCell cell in row.Cells) { MessageBox.Show("" + cell.Value.ToString() +" | " + cell.Column.Key); } } }
But it's not working, am I missing something?
This code doesn't make a lot of sense to me - so maybe I don't understand what you are trying to do.
The first thing this code does is check the value of the "Seleccionar" cell in the ActiveRow of the grid. This is before you have even started to loop through the rows. So you are only looping if the ActiveRow is checked. Is that what you want? Seems pretty arbitrary to base this on the ActiveRow.
I would think that what you want to do here is loop and look at the row inside the loop and check each row's "Seleccionar" value as you loop. No?
I only want to loop through the rows that are checked (value "seleccionar")
Hi Wiliam,
Yes... I already answered this question in your other post here.
Awesome, thanks.
Another question, is it possible to start looping from a certain index? Let's say from cell[2]?
Yeah, that's what I thought. So I don't understand why you are checking the ActiveRow, or why you are checking it before you even get into the loop. What you want o do is check the value of the cell for each row inside the loop.
foreach (UltraGridRow row in this.grdPart.Rows) { if (false == (bool)row.Cells["Seleccionar"].Value) continue; foreach (UltraGridCell cell in row.Cells) { MessageBox.Show("" + cell.Value.ToString() + " | " + cell.Column.Key); } }
foreach (UltraGridRow row in this.grdPart.Rows) { if (false == (bool)row.Cells["Seleccionar"].Value) continue;
foreach (UltraGridCell cell in row.Cells) { MessageBox.Show("" + cell.Value.ToString() + " | " + cell.Column.Key); } }