We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Problem with drag and drop selection in GridGroupingControl

Thread ID:

Created:

Updated:

Platform:

Replies:

119834 Aug 6,2015 04:33 AM UTC Sep 8,2015 04:24 AM UTC WinForms 14
loading
Tags: GridGroupingControl
Andrew Sullivan
Asked On August 6, 2015 04:33 AM UTC

Hello,

Background: I am setting up drag and drop functionality between two GridGroupingControl grids. Is is important that the selection mode be set to MultiExtended. I'm using the following knowledge base example to help set this functionality up:
https://www.syncfusion.com/kb/581/how-to-drag-and-drop-in-the-gridgroupingcontrol

Problem: It seems that because the drag and drop is initiated from the Mouse Down event, you have to be careful to make a selection first, and then using a new click, click and drag your selection to the destination. If no rows are selected, and you try to click and drag a single row in one motion, that row will not be selected because the DoDragDrop method gets called before the row is actually selected. SelectedRecords is empty. Even worse would be the situation where a row is already selected, but then without pressing the control or shift key, you try to click and drag a new different row in one motion. You would expect that the new record would be dragged. But instead, because the new record won't be selected, the previously selected row will will get added to SelectedRecords because it was still selected when you started the click and drag. This is an undesired result.

Question: 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?

Thank you for your assistance!

-Andrew

Adhikesevan Kothandaraman [Syncfusion]
Replied On August 7, 2015 10:52 AM UTC

Hi Andrew,

Thank you for your interest in Syncfusion product.

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.
grid.Table.SelectedRecords.Clear();

GridTableCellStyleInfo style = tableControl.Model[rowIndex, colIndex];

//Add the current record to the selection
grid.Table.SelectedRecords.Add(style.TableCellIdentity.DisplayElement.ParentRecord);


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.

Sample:
http://www.syncfusion.com/downloads/support/forum/119834/ze/DragDropInSingleClick-746517056

Please let me know if you have any concern.

Regards,
Adhi.

Andrew Sullivan
Replied On August 9, 2015 05:53 AM UTC

Hi Adhi,

Thank you for your response. Using the code that you provided, I was able to add the current row to the selection, as well as clear the selection.

However, there is still a visual problem occurring. When I add or clear rows from SelectedRecords in the TableControlMouseDown event, the grid in the application does not reflect the change to the SelectedRecords until either the mouse is dragged during the click or the mouse button is released. So, my question is, 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? It is weird that, after clicking a record, you either have to move the mouse or release the mouse button for the row to be visually selected in the application.

Thank you.

Andrew Sullivan
Replied On August 9, 2015 05:32 PM UTC

I have one additional question I forgot to ask. How is the row index determined? In my code I either determine the index of the current row, or determine the index of a record from a SelectedRecordsCollection:

Point pt = new Point(e.Inner.X, e.Inner.Y);
int row, col;
tableControl.PointToRowCol(pt, out row, out col);

Or

SelectedRecordsCollection recs = grid.Table.SelectedRecords;
foreach (SelectedRecord rec in recs)
{
        Debug.WriteLine(rec.record.GetRowIndex());
}

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?

Adhikesevan Kothandaraman [Syncfusion]
Replied On August 10, 2015 10:07 AM UTC

Hi Andrew,

Thank you for your update.


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


Sample:
http://www.syncfusion.com/downloads/support/forum/119834/ze/DragDrop-485386315

Please let me know if you have any other concerns.

Regards,
Adhi.

Andrew Sullivan
Replied On August 16, 2015 08:07 PM UTC

Hi Adhi,

Sorry for the delayed response. Thank you for your comment. That answers my questions perfectly.

However, a couple mores questions have come up as I've been developing my application:

Question 1

As I drag a record from one gridgroupingcontrol into another, the DragDropEffects changes to Copy once I hover the mouse over the destination control. This is the code I'm using:

private void grid_DragOver(object sender, DragEventArgs e)
{
// shows the dragdrop effects.
if(e.Data.GetDataPresent(typeof(SelectedRecordsCollection)))
{
e.Effect = DragDropEffects.Copy;     
}
}

This is great. But, I only want the copy effect to occur when the mouse is hovering over a record in the destination grid. How do I do that? I'm also planning on using multiple column grouping in some of my destination grids. In that case, how do I limit the copy effect to only occur when the mouse is hovered over, say, the summary line of the child group?


Question 2

How do I highlight a row when the mouse hovers over the row (regardless of whether or not a DragDrop is occuring)? When I say highlight, I don't mean select. I'd like to change the background color of the row that the mouse is over. Once the mouse moves away, I'd like to un-highlight the row. Do I use the TableControlCellMouseHover event? Do you have example code showing this?


Thank you very much for your assistance as always!

Andrew Sullivan
Replied On August 16, 2015 11:24 PM UTC

Question 3

I'm currently using ListBoxSelectionMode = SelectionMode.MultiExtended. It's working well as the most important functionality in my application is selecting records and dragging them, not editing them. However, I want to implement a way to be able to edit individual cell values, say if you were to double click the cell. Instead of a direct question, I'm looking for some advice on the best way to approach this. 

One way I could see this working is during the double-click event, the ListBoxSelectionMode could be disabled, and edits could be allowed until the edit is complete. At that point, the ListBoxSelectionMode would be re-enabled. Is there a better way to do this?

Adhikesevan Kothandaraman [Syncfusion]
Replied On August 18, 2015 01:28 PM UTC

Hi Andrew,

Sorry for the delay caused.

We have provide solution for your queries in below table.


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;
this.gridGroupingControl1.QueryCellStyleInfo += gridGroupingControl1_QueryCellStyleInfo;


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.


Andrew Sullivan
Replied On August 25, 2015 04:52 AM UTC

Hi Adhi,

As usual, thank you for your comments. They are very helpful.

For Query 1: 

I don't think I was too clear in my initial question. During the drag and drop process, the mouse icon changes based on whether or not a drop is allowed. I would like to fine tune where a drop is allowed within a grid. For example, with my grid, I have two grouping levels. I would like to only be able to drop on a summary line of a child group. To illustrate what I'm after, I have attached an image showing where I'd like to limit dropping to. Most importantly, 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?

For Query 2:

Your code snippet worked beautifully. Thank you!

For Query 3:

I'm running into an odd issue here. I have the code set up as you have it in the example code you attached. However, the TableControlCurrentCellStartEditing event is not getting hit (I have put a break point in my code). Interestingly, if I comment out the TableControlMouseDown event on my grid, the TableControlCurrentCellStartEditing event then gets hit, and the code you provided works great. I have attached a snippet of my code. Do you know why this would be happening? 


Thank you!

Attachment: DragDrop_75575b1c.zip

Adhikesevan Kothandaraman [Syncfusion]
Replied On August 27, 2015 03:58 AM UTC

 
Hi Andrew,

Thank you for using Syncfusion product.

We have analyzed your query and we will update you the further details on 27th  August, 2015. We appreciate your patience until then.

Regards,
Adhi.


Andrew Sullivan
Replied On August 28, 2015 02:03 PM UTC

I look forward to your response!

-Andrew

Andrew Sullivan
Replied On August 31, 2015 07:01 PM UTC

Any update on this Adhi? Are you having trouble replicating the issue I am experiencing with query 3?

Adhikesevan Kothandaraman [Syncfusion]
Replied On September 1, 2015 05:16 AM UTC

Hi Andrew,

We deeply regret for the delay caused.


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
 
Regards,
Adhi.

Andrew Sullivan
Replied On September 4, 2015 08:53 PM UTC

Hi Adhi,

Thank you for you support! I have been able to resolve my outstanding issues.

-Andrew

Ranjani Prabhakaran [Syncfusion]
Replied On September 8, 2015 04:24 AM UTC

Hi Andrew,
Thanks for the update.
Please let us know if you have any query.
Regards,
Ranjani

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;