How can I determine which rows are selected in the grid? It’s easy to determine which row is selected with:
owningTaskId := StrToInt((gantt1.Grid.FocusedCell.GridNode.ListItemWhenDataBound() as DataRowView).Item['id'].ToString)
but how do I determine which multiple rows are selected?
Often in gui controls like the GTP.NET there is a distinct difference between “select” and “focus”. The “thing” with focus can almost always be only one, and focus often mean keyboard-focus (where will the key-strokes go).
Selections can often consist of many “items”, often refered to as multi-select.
So in the grid there is only one Focused cell: gantt1.Grid.FocusedCell. And there are possibly many selected cells: ArrayList al=gantt1.Grid.GridStructure.SelectedCells();
You will need to iterate thru the list of selected cells and get to their GridNode just as you did with the focused cell.
Each Cell has a Selected property that is true or false. You can programatically set this if needed.
How to select a row in the gantt area when a node in the grid is selected?
Whenever a cell is selected or de-selected the event Grid.OnCellSelectChanged is fired. If you implement this event and check if the event is fired due to a selection (nowSelected==true), look up the owning GridNode, find the corresponding GanttRow and check if it contains any time items. If so, select it:
private void Grid_OnCellSelectChanged(Cell cell, CellSelectChangedEventArgs cellSelectChanged)
if (gr.Layers.Count>0 && gr.Layers.Count>0 )
Note; time items has a property Selected that will be set upon selection, but if this state actually shows on screen depends on the TimeItemLayout for the given time item… Try TimeItemLayout.SelectHandles=Color.Black;
Note2; You can set gr.Layers.Selected=true, but then the earlier selected time items will not be un-selected.