Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / Convert SelectedRowsCollection to RowsCollection

Convert SelectedRowsCollection to RowsCollection

New Discussion
Jayson Hinkel
Jayson Hinkel asked on Oct 31, 2016 3:29 PM

Is it possible to convert a SelectedRowsCollection to a RowsCollection?

SelectedRowsCollection rows = ultraGrid1.SelectedRows;

RowsCollection rc = (RowsCollection)rows;

Sign In to post a reply

Replies

  • 0
    [Infragistics]Joshee
    [Infragistics]Joshee answered on Oct 26, 2016 8:18 PM

    Hi Jayson,
    You can use the GetRowEnumertor method to loop through the entire WinGrid or all rows in a particular band or rows collection.
    It is not possible to convert SelectedRowsCollection to a RowsCollection.

    Thanks,
    Josheela

    • 0
      Jayson Hinkel
      Jayson Hinkel answered on Oct 27, 2016 12:41 AM

      Do you have a few lines of code to demo this?

      Here's what I tried:

      UltraGridBand band = ultraGrid1.DisplayLayout.Bands[1];

      IEnumerator allRowsEnumerator = (RowsCollection)ultraGrid1.Rows.GetRowEnumerator(GridRowType.DataRow, band, null);

      How can I then convert the allRowsEnumerator (either through a loop, or with some type of direct conversion) to a RowsCollection?

      • 0
        Jayson Hinkel
        Jayson Hinkel answered on Oct 27, 2016 12:48 AM

        Josheela,

        Thank you for the link:
        http://www.infragistics.com/help/winforms/wingrid-looping-through-the-entire-grid

        I'd like to use the Enumerator to build a RowsCollection to pass to another method.

        UltraGridBand band = this.ultraGrid1.DisplayLayout.Bands[1];
        foreach (UltraGridRow row in band.GetRowEnumerator(GridRowType.DataRow))
        {
        	// Write code to process the row
        	// Here is where I'd like to build a collection of rows (RowsCollection) to pass to another method.
        }

         

      • 0
        [Infragistics]Joshee
        [Infragistics]Joshee answered on Oct 27, 2016 4:28 PM

        Hi Jayson,

        GetRowEnumerator method gets all the rows associated with Bands[1].As you see in the below screenshot I have selected all rows in the Bands[1].

      • 0
        Jayson Hinkel
        Jayson Hinkel answered on Oct 27, 2016 8:13 PM

        I would like to build a Collection of Rows, something like the following:

        GridRowType rowTypes = GridRowType.DataRow;
        UltraGridBand band = this.ultraGrid1.DisplayLayout.Bands[1];
        IEnumerable enumerator = band.GetRowEnumerator(rowTypes);
         

        RowsCollection rowsCollection = new RowsCollection();

        foreach  (UltraGridRow row in enumerator)
        {
            rowsCollection.Add(row);
        }

        Is this possible?

      • 0
        [Infragistics]Joshee
        [Infragistics]Joshee answered on Oct 28, 2016 4:26 PM

        As you can see, GetRowEnumerator returns a RowsCollection of GridRowType. But at this point we don't have a direct way of converting it to a RowsCollection.

        It would be great if you can provide me a sample of your own so that I will have a clear understanding of your requirement and can assist you better.

        Looking forward to hearing you back.

      • 0
        Jayson Hinkel
        Jayson Hinkel answered on Oct 28, 2016 6:06 PM

        Again, I'd like to pass a RowsCollection to another method to perform some operations on Rows in the UltraGrid. I'd like to be able to pass only the Rows that I need, so that I don't have to perform the operation on all Rows.

        Example:

        private void GetRows()
        {
            GridRowType rowTypes = GridRowType.DataRow;
            UltraGridBand band = this.ultraGrid1.DisplayLayout.Bands[1];
            IEnumerable enumerator = band.GetRowEnumerator(rowTypes);
            
            RowsCollection rowsCollection = new RowsCollection();
            
            //Either build RowsCollection via Loop
            foreach  (UltraGridRow row in enumerator)
            {
                rowsCollection.Add(row);
            }
            
            //Or, cast IEnumerable to RowsCollection
            rowsCollection = (RowsCollection)enumerator;
        } 

        private void UpdateRows(RowsCollection rows = null)
        {
            if (rows != null)
            {
                foreach (UltraGridRow r in rows)
                {
                    //Perform operation on SPECIFIED rows here
                }
            }
            else
            {
                rows = ultraGrid1.Rows;
                
                foreach (UltraGridRow r in rows)
                {
                    //Perform operation on ALL UltraGrid rows here
                }
            }
        }

      • 0
        [Infragistics]Joshee
        [Infragistics]Joshee answered on Oct 28, 2016 9:45 PM

        Is it possible for you to change the method to use IEnumerable as argument instead of rows Collection so that you can pass the enumerator which itself is the RowsCollection.

      • 0
        Jayson Hinkel
        Jayson Hinkel answered on Oct 31, 2016 2:59 PM

        Not really.  The issues is that sometimes I am passing a RowsCollection, and in other instances it may be the IEnumerable.  While I could certainly modify the receiving method to accommodate both, to me, it would just make more sense to be able to always pass a RowsCollection; i.e. – to take whatever form the rows are in and convert them to a RowsCollection.  I'd really like to see this as a feature.

        Thanks,
        -Jayson 

      • 0
        [Infragistics]Joshee
        [Infragistics]Joshee answered on Oct 31, 2016 3:29 PM

        Hi Jayson,

        Currently there is no method available to convert an IEnumerable to a RowsCollection. You can Submit a Feature Request  and perhaps this can be added as a feature in a future release.

        Thank you for using Infragistics Components.
        Please let me know if I can provide you any further assistance.

        Josheela

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Jayson Hinkel
Favorites
0
Replies
10
Created On
Oct 31, 2016
Last Post
9 years, 12 months ago

Suggested Discussions

Tags

Created by

Created on

Oct 31, 2016 3:29 PM

Last activity on

Oct 31, 2016 3:29 PM