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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GetSelectedRanges during GridSelectionChangedEventHandler

Thread ID:

Created:

Updated:

Platform:

Replies:

45999 Jul 3,2006 10:54 PM Jul 7,2006 01:14 AM Windows Forms 5
loading
Tags: GridControl
Leow Kah Man
Asked On July 3, 2006 10:54 PM

Hi, During GridSelectionChangedEventHandler event, I tried to GetSelectedRanges but I keep getting the previous range. As the event is named "...Changed...", I would assume that it should be triggered only after the selection has changed. Please see attached.

GetSelectedRanges_During_SelectionChanged.zip

Administrator [Syncfusion]
Replied On July 4, 2006 12:07 PM

Hi Leow, The reason is that selection is not cleared when the user moves the currentcell out of a selected range. You need to set the ExcelLikeCurrentCell behavior to TRUE. Here is a code snippet. this.gridControl1.ExcelLikeCurrentCell = true; Try this code to find the newly selected range in a grid . Here is a code snippet. private void gridControl1_SelectionChanged(object sender, Syncfusion.Windows.Forms.Grid.GridSelectionChangedEventArgs e) { if (e.Reason != GridSelectionReason.MouseDown && e.Reason != GridSelectionReason.Clear) { GridRangeInfoList g; gridControl1.Selections.GetSelectedRanges(out g, true); Console.WriteLine(g.Info + ":::::" + e.Reason); } } Let me know if this helps. Best Regards, Haneef

Leow Kah Man
Replied On July 4, 2006 09:55 PM

1. Select a cell, 2. hold the control button, select another cell. Your code will prevent the 2nd one from firing, because on the 2nd time, the e.Reason is MouseDown. If I choose to use only e.Reason != Clear, then I will see that MouseDown gets fired twice on (1).

Leow Kah Man
Replied On July 5, 2006 02:10 AM

if (!e.Range.IsEmpty && ( e.Reason == GridSelectionReason.SetCurrentCell || e.Reason == GridSelectionReason.ArrowKey || e.Reason == GridSelectionReason.MouseDown ) ) Perhaps this solves my problem. What do you think?

Administrator [Syncfusion]
Replied On July 5, 2006 12:08 PM

Hi Leow, Thanks for your update. The reason is that when you click the specified cell, the grid clears the old selection with e.Reason = GridSelectionReason.MouseDown and also add the new selection with the same e.Reason = GridSelectionReason.MouseDown. To find the selection type( Clear/Add selection ) with e.Reason = GridSelectionReason.MouseDown, you can use below to achieve this issue. if (e.Reason != GridSelectionReason.MouseDown && e.Reason != GridSelectionReason.Clear) Or if (!e.Range.IsEmpty && ( e.Reason == GridSelectionReason.SetCurrentCell || e.Reason == GridSelectionReason.ArrowKey || e.Reason == GridSelectionReason.MouseDown ) ) Let me know if this helps. Best Regards, Haneef

Leow Kah Man
Replied On July 7, 2006 01:14 AM

Yes it does, thank you.

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

;