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.
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.
Here is a sample form.
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<SampleData> dataToBind; public Form1() { InitializeComponent(); grid = new UltraGrid(); this.Controls.Add(grid); grid.Dock = DockStyle.Fill; grid.KeyDown += Grid_KeyDown; dataToBind = new List<SampleData>() { 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(); } } }
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.