Query 1: During the MouseDown, when control or shift is not pressed, is it possible to programmatically select the row that the mouse is over and un-select all other records prior to starting the DoDragDrop operation? |
If you want to remove all selected records from the selection and select the current record for drag and drop, you can use the “TableControlMouseDown” event. Please refer the below code snippet, Code Snippet: //Clear all the selected records from the selection. GridTableCellStyleInfo style = tableControl.Model[rowIndex, colIndex]; //Add the current record to the selection |
Query 2: Is is important that the selection mode be set to MultiExtended. |
There is no restrictions on the selection mode, you can use any ListBoxSelectionMode for drag and drop except None. |
OrPoint pt = new Point(e.Inner.X, e.Inner.Y);int row, col;tableControl.PointToRowCol(pt, out row, out col);
However, I get index values that don't make sense. I'll have only 2 rows in a grid table, but for some reason it will return row indexs of 4 and 5 for those two rows. There is no filter on the grid. What is going on there?SelectedRecordsCollection recs = grid.Table.SelectedRecords;foreach (SelectedRecord rec in recs){Debug.WriteLine(rec.record.GetRowIndex());}
Query 1: is it possible to visually update the grid control in the application with the changes to the SelectedRecords before the mouse down event is complete? |
If you want to apply the changes before the TableControlMouseDown event, you can refresh the grid it will allow you to apply the changes.Please refer the code snippet, Code Snippet: grid.Refresh(); |
Query 2: How is the row index determined? |
In the GridGroupingControl, it has the pre-assigned rows that are Table Caption, GroupDropArea, Header section as well as the AddNewRecord section. Since these rows are already allocated your data is starts loading after from these index. If you want to get the actual row index, you can refer the below KB article which will suggest you to get the actual row index using record. KB Link: https://www.syncfusion.com/kb/497/how-do-i-get-the-position-of-a-row-in-datasource-from-the-currentcells-rowindex |
private void grid_DragOver(object sender, DragEventArgs e)
{
// shows the dragdrop effects.if(e.Data.GetDataPresent(typeof(SelectedRecordsCollection))){
e.Effect = DragDropEffects.Copy;
}
}
Query1: want the copy effect to occur when the mouse is hovering over a record in the destination grid. How do I do that? |
If you want to check the drag drop copy only effect on the particular cell, you can add your condition to the DragDrop event. Please refer the below code snippet, Code Snippet: if ((style.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell || style.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell)) { e.Effect = DragDropEffects.Copy; } else e.Effect = DragDropEffects.None; |
Query 2: How do I highlight a row when the mouse hovers over the row |
If you want to change the row color based on the mouse hover position, it can be achieved by handling the TableControlCellMouseHoverEnter, TableControlCellMouseHoverLeave and QueryCellStyleInfo events. Please refer the below code snippet, Code Snippet:
//Invoke the events to change the color of row during the mouse hover. this.gridGroupingControl1.TableControlCellMouseHoverEnter += gridGroupingControl1_TableControlCellMouseHoverEnter; this.gridGroupingControl1.TableControlCellMouseHoverLeave += gridGroupingControl1_TableControlCellMouseHoverLeave;
int hoveredIndex =-1;
void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e) { if (hoveredIndex == e.TableCellIdentity.RowIndex) { //Set the back color for the mouse hoverd row. e.Style.BackColor = Color.LightBlue; } }
void gridGroupingControl1_TableControlCellMouseHoverLeave(object sender, GridTableControlCellMouseEventArgs e) { //Reset the mouse hoverd position while leave the row. hoveredIndex = -1; }
void gridGroupingControl1_TableControlCellMouseHoverEnter(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCellMouseEventArgs e) { //Set the hovered row index to change the backcolor. hoveredIndex = e.Inner.RowIndex; this.gridGroupingControl1.TableControl.Refresh(); |
Query 3: the ListBoxSelectionMode could be disabled, and edits could be allowed until the edit is complete. At that point, the ListBoxSelectionMode would be re-enabled. |
This can be done by using CurrentCellStartEditingEvent and EditingComplete event . Please refer below code snippet. Code Snippet: void gridGroupingControl1_TableControlCurrentCellEditingComplete(object sender, GridTableControlEventArgs e) { gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.MultiExtended; gridGroupingControl1.TableOptions.AllowSelection = GridSelectionFlags.None; }
void gridGroupingControl1_TableControlCurrentCellStartEditing(object sender, GridTableControlCancelEventArgs e) { gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.None; e.TableControl.CurrentCell.Activate(e.TableControl.CurrentCell.RowIndex, e.TableControl.CurrentCell.ColIndex); |
Sample:
http://www.syncfusion.com/downloads/support/forum/119834/ze/CS2000311562
Please let me know if you have any other concern.
Thanks,
Adhi.
Query 1 I would like for the mouse icon to change during the drag as the mouse hovers/moves over different records, before the drop is made. Is this possible? |
To change the mouse icon during the dragdrop process. You can make use of below code snippet. It may help you to change the cursor in mouse hover. Code Snippet: //Change the mouse cursor image to hand. this.gridGroupingControl1.Cursor = Cursors.Hand; |
Query 2 However, the TableControlCurrentCellStartEditing event is not getting hit. |
We were analyzed your reported scenario at our end. We could not able to reproduce the issue at our end. If you could able to reproduce the issue in simple sample or modify the attached sample it will be more help full for us to provide the prompt solution. Sample: http://www.syncfusion.com/downloads/support/forum/119834/ze/CurrentCellStartEditing1163403221 |