I need to select one column and one row in a grid. I can change these selection using CTRL key with view. But how can i change both column and row selection dynamically (through code in C#)?
Hi,
Sorry, i was out of the office Friday, so i haven't had a chance to review the forums until this morning.
As for your question, i reviewed the code, and we explicitly check to see if the ctrl or shift key is down, whenever switching between different types of selection (i.e. column, cell and row). Which is why when you select a column, then a row, only the row is selected.
Unfortunately this was just a case we never considered.
However, you could just change the style of the row and column your self, when clicking an active cell and forget the row and/or column selection.
Each Column and Row has a CellStyle property, so you can use that to change the appearance, along with the ActiveCellChanging event, which gives you both the activeCell and previously activeCell, so that you can set the new one, and reset the previous one to null.
Hope this helps,
-SteveZ
Hi Stephen,
Yes it is working fine when I select CellStyle property of Row & Column in ActiveCellChanging event like here.
private void gTable_ActiveCellChanging(object sender, Infragistics.Silverlight.ActiveCellChangingEventArgs e) { if (e.PreviousActiveCell != null) { e.PreviousActiveCell.Column.CellStyle = null; ((Row)e.PreviousActiveCell.Row).CellStyle = null; } Style s = new Style(typeof(CellControl)); s.Setters.Add(new Setter(CellControl.BackgroundProperty, new SolidColorBrush(Colors.LightGray))); ((Row)e.NewActiveCell.Row).CellStyle = s; e.NewActiveCell.Column.CellStyle = s; }
Now the problem is....the default color on Selected Column/Row is different. I tried to change the default color using Expression Blend (http://help.infragistics.com/Help/NetAdvantage/Silverlight/2009.1/CLR3.5/html/SL_DesignersGuide_Editing_Style_Properties_Using_Expression_Blend.html) i.e. I select ActiveSlected item from following element tree.
But it change the color of entire Grid content. Kindly help me to synchronize the colors. Thanks
You can just change the background of the "Root" and remove the Alternate VisualState. (this will make sure that the alternate color is disabled).
You can also turn off Row and Column and selection so that your Cell's won't get put into a selected visualState.
Hi Steve, Thank you for the reply. But I need ONE Row and ONE Column selection functionality in Grid. Acutally I need to perform some calculation based on Column selection and I need to display Line Chart based on Row selection. So I need both selection in Grid. However when data rebind/refresh in Grid(based on some events in view), I need to select by default one row and one column which I am not able to do via C# code. Moreover when Active cell is changed then I also need to select active cell row and active cell column as well which I am also not been able to do. However I am changing their background color in ActiveCellChanging event (as you suggested) BUT this column and row are not selected so its not firing the ActiveSelectionChanged event.
I could also not understand, why CTRL key is required when selecting row and column in View mode as SelectionSettings.SelectedColumns and SelectionSettings.SelectedRows are two independent collections. So if we are selecting multiple Rows then control key make sense as it is effecting on ONE collection (SelectedRows) but selecting Column has no impact on SelectedRows collection so it should also work independently.
This is the detail of my requirements. Kindly advice me how I can achive it using Infragistic WebGrid.
So the issue with the ctrl key is b/c of a timing issue, when attempting to selecting more than one different type in the ActiveCellChanged event.
However, i believe i found a reasonable workaround:
void grid_ActiveCellChanged(object sender, EventArgs e)
{
this.Dispatcher.BeginInvoke(() =>
grid.SelectionSettings.SelectedColumns.Clear();
grid.SelectionSettings.SelectedRows.Clear();
grid.SelectionSettings.SelectedRows.Add((Row)grid.ActiveCell.Row);
grid.SelectionSettings.SelectedColumns.Add(grid.ActiveCell.Column);
});
}
This will force your selection to happen after all the mouse down functionality that we're doing has completed and thus avoid the timing issue.