Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / Row.Selected and Selected.Rows.Add behavior in Ultragrid

Row.Selected and Selected.Rows.Add behavior in Ultragrid

New Discussion
John Worthy
John Worthy asked on Apr 10, 2018 7:57 PM

If I select a row programmatically by setting the row's Selected property to true or by adding the row to the selected rows collection (Rows.Add or Rows.AddRange), I lose the ability to Shift+Up key or Shift+Down key to begin a multi select operation. The same is true for Shift+Left mouse click to select a range.

In addition to selecting the row, I have activated it as well.

The results I'm seeing are: Programmatically select and activate a row in the grid, Shift+Down key selects and activates the next row in the grid without preserving the selected state of the original row. Shift+Down key again will begin the multi-row select operation.

I can PerformAction(ToggleRowSel) to achieve the desired results for a singe row, but this doesn't help when I'm trying to AddRange.

I am currently running v17.2 in VS2017.

Is this the expected behavior? Is there a way to achieve the desired behavior with AddRange other than iterating the entire range and calling PerformAction on each row?

Thanks.

Sign In to post a reply

Replies

  • 0
    Divya Jain
    Divya Jain answered on Apr 10, 2018 3:12 PM

    Hello John, 

    Thank you for posting to infragistics. 

    In the grid you can select and activate an UltraGridRow programmatically by setting the UltraGrid.ActiveRow property to activate the row, and use the Rows property of the selected object to select a row. Something like this

    this.ultraGrid.ActiveRow = row;
    this.ultraGrid.Selected.Rows.Add( row ); 

    and by doing this I did not lose the ability to Shift+Up key or Shift+Down key. 

    In order to address the issue and reproduce it at my environment I would like you to provide me a small isolated sample with the step to take it.

    Looking forward to hear you back.

    • 0
      John Worthy
      John Worthy answered on Apr 10, 2018 4:51 PM

      Here is a sample form.

      1. Click on a cell in the second row of the grid (not in the currently active row).
      2. Press Shift+Space to select the row. (The row is now selected and active).
      3. Press Shift+ Down key.
      4. Next row is selected but the first row is no longer selected.

      public partial class Form1 : Form
          {
              public class SampleData
              {
                  public int Id { get; set; }
                  public string Description { get; set; }
      
                  public SampleData(int id, string description)
                  {
                      Id = id;
                      Description = description;
                  }
              }
      
              private UltraGrid grid;
              private List dataToBind;
              public Form1()
              {
                  InitializeComponent();
      
                  grid = new UltraGrid();
                  
                  this.Controls.Add(grid);
                  grid.Dock = DockStyle.Fill;
                  grid.KeyDown += Grid_KeyDown;
                  dataToBind = new List()
                      {
                          new SampleData(1, "Sample Item 1"),
                          new SampleData(2, "Sample Item 2"),
                          new SampleData(3, "Sample Item 3"),
                          new SampleData(4, "Sample Item 4"),
                          new SampleData(5, "Sample Item 5"),
                          new SampleData(6, "Sample Item 6"),
                          new SampleData(7, "Sample Item 7"),
                          new SampleData(8, "Sample Item 8"),
                      };
      
                  grid.DataSource = dataToBind;
              }
      
              private void Grid_KeyDown(object sender, KeyEventArgs e)
              {
                  if (e.KeyCode == Keys.Space && e.Modifiers == Keys.Shift)
                  {
                      UltraGridRow row = grid.ActiveRow;
                      grid.ActiveCell = null; // Just for kicks
                      grid.ActiveRow = null;  // Just for kicks
                      grid.ActiveRow = row;
                      grid.Selected.Rows.Add(row);
                      //grid.PerformAction(UltraGridAction.ToggleRowSel);
                  }
                  if (e.KeyCode == Keys.A && e.Modifiers == Keys.Control)
                  {
                      grid.Selected.Rows.AddRange((UltraGridRow[])grid.Rows.All);
                      grid.Selected.Rows[0].Activate();
                  }
              }
          }

      • 0
        Divya Jain
        Divya Jain answered on Apr 10, 2018 7:57 PM

        Hello,

        Thank you for providing the information.

        I did some research and find the information in this post .

        To fix this, you can cast the grid into an ISelectionManager and call the SetPivotItem method and pass in the row or cell that should begin the range selection.

        Please let me know if you need further assistance.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
John Worthy
Favorites
0
Replies
3
Created On
Apr 10, 2018
Last Post
7 years, 10 months ago

Suggested Discussions

Tags

Created by

Created on

Apr 10, 2018 7:57 PM

Last activity on

Feb 16, 2026 9:50 PM