Skip to content

Loop through UltraGird

New Discussion
william gm
william gm asked on Jan 31, 2017 2:30 PM

Hello. 

I have an UltraGrid that loads from an Excel file.

grdPart

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

Sign In to post a reply

Replies

  • 0
    william gm
    william gm answered on Jan 26, 2017 3:17 PM

    Here is a link to the image.

    https://postimg.org/image/3qo44owpj/

  • 0
    Mike Saltzman
    Mike Saltzman answered on Jan 26, 2017 6:30 PM

    Hi William,

    
    

                foreach (UltraGridRow row in this.ultraGrid1.Rows)
                {
                    foreach (UltraGridCell cell in row.Cells)
                    {
                        Debug.WriteLine(cell.Value.ToString(), cell.Column.Key);
                    }
                }

    • 0
      william gm
      william gm answered on Jan 26, 2017 6:44 PM

      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?

      • 0
        Mike Saltzman
        Mike Saltzman answered on Jan 27, 2017 2:36 PM

        Hi William,

        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?

      • 0
        william gm
        william gm answered on Jan 27, 2017 2:42 PM

        I only want to loop through the rows that are checked (value "seleccionar")

      • 0
        Mike Saltzman
        Mike Saltzman answered on Jan 27, 2017 2:55 PM

        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);
                        }
                    }

      • 0
        william gm
        william gm answered on Jan 30, 2017 6:06 PM

        Awesome, thanks.

        Another question, is it possible to start looping from a certain index? Let's say from cell[2]?

      • 0
        Mike Saltzman
        Mike Saltzman answered on Jan 31, 2017 2:30 PM

        Hi Wiliam, 

        Yes… I already answered this question in your other post here

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
william gm
Favorites
0
Replies
8
Created On
Jan 31, 2017
Last Post
9 years, 2 months ago

Suggested Discussions

Tags

Created by

Created on

Jan 31, 2017 2:30 PM

Last activity on

Feb 16, 2026 9:44 PM