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.

Mulitple cell selection

Thread ID:

Created:

Updated:

Platform:

Replies:

10287 Jan 28,2004 12:30 PM Sep 24,2004 11:30 AM Windows Forms 12
loading
Tags: GridControl
Philip Bishop
Asked On January 28, 2004 12:30 PM

How can i tell when the user clicks another cell while holding down the ctrl key to select multiple cells. I want to be able to see that they have clicked another cell but more so to see that they click another cell in a different column. So if they click row 1 in column one and then hold down the ctrl key and click the cell in row1, column2 i want to do something knowing they clicked multiple cells in DIFF columns. Thanks

Administrator [Syncfusion]
Replied On January 28, 2004 01:37 PM

If I understand what you want, I think you can do it by subscribing to the CellClick event.
Private Sub gridControl1_CellClick(sender As Object, e As GridCellClickEventArgs)
   ''check for ctl+click
   If(Control.ModifierKeys And Keys.Control) <> 0 Then
      
      Dim rangeList As GridRangeInfoList
      If Me.gridControl1.Selections.GetSelectedRanges(rangeList, False) Then
         Dim clickedCell As GridRangeInfo = Me.gridControl1.CurrentCell.RangeInfo
         Dim clickedCellCol As GridRangeInfo = GridRangeInfo.Col(Me.gridControl1.CurrentCell.ColIndex)
         Dim newCol As Boolean = True
         Dim range As GridRangeInfo
         For Each range In  rangeList
            If range <> clickedCell And range.IntersectsWith(clickedCellCol) Then
               newCol = False
               Exit ForEach
            End If
         Next range
         If newCol Then
            Console.WriteLine("ctl+click into new column")
         End If
      End If
   End If 
End Sub ''gridControl1_CellClick

Philip Bishop
Replied On January 29, 2004 06:34 AM

Clay, First thanx for getting back to us so fast. The code you sent kinda sorta works. If i click row one column one cell and then hold the ctrl key and click row one column 2 it works fine. If i keep the ctrl key down and click row 2 column 2 then its like your code u sent starts over. We are trying to disable a group box and its contents based on whether or not they click a range in one column which is ok versus a range of any other type which isnt and in turn should disable the group box. In the selection changing even in this sample u will see that we do this if they grab a range with the mouse and it works fine. Your code seems to be ok until they click multiple cells in another column after the orginal column cell was clicked. The only thing we werent for sure on was the one line of code u had that wouldnt work in VB. It was this line If range <> clickedCell And range.IntersectsWith(clickedCellCol) Then the <> wouldnt work in vb. we would get the message use the IS operator when comparing 2 reference types...so we coded it like this but we are not for sure if its right If Not range.Equals(clickedCell) And range.IntersectsWith(clickedCellCol) Then I am attaching a sample below. click the first cell in row one column one. then hold down the ctrl key and click row one column two and notice the group box disable..still holding down the ctrl key now click column 2 row 2 and notice the gray box re enable itself. Thats what we are trying to prevent because its still outside the cell. That is where its like ur code is starting over because its now in another column like it forgot the column one row one was clicked cellclick_3999.zip

Administrator [Syncfusion]
Replied On January 29, 2004 07:30 AM

I think the code is indentifying when a new column is clicked. In your senario of ctl+clicking 1,2 and then 2,2. Clicking 2,2 does not mark a new column, does it? And if you step through the code, the bool newCol is false in this case which is correct since it is not a new column. But you have this code: If newCol Then GroupBox1.Enabled = False Else GroupBox1.Enabled = True End If So, in this case when it is not a new column, you explicitly enable the groupbox which is what you see. So, the question is: Exactly when do you want to enable the groupbox afer disabling it? It is not when you ctl-click into the same column which is what your code is dointg now, is it? Once you decide what this answer is, I think you would move the GroupBox1.Enabled = True to some other position in your code to implement what you need.

Philip Bishop
Replied On January 29, 2004 12:49 PM

Ok so i see what ur saying and I think I may of figured out where to set that groupbox to enabled. When i make that work however it messes with the code i have in the selectionchanging event to try to and grab when someone selects a range with the mouse. Maybe I am making this to hard. Let me ask this another way. Whats the easiest way that if someone clicks any cell that isnt in the column that the first cell was clicked in it disables that group box whether its a ctrl clicking or shift key or grabbing a range with ur mouse. they can do a range in one column and thats ok. so anytime they click out of the original column i want to disable the group box and anytime it gets reset where only one cell is selected it gets enabled. let me know

Administrator [Syncfusion]
Replied On January 29, 2004 01:19 PM

I think you can do all this in the SelectionChanged event. cellclick_6346.zip

Philip Bishop
Replied On January 30, 2004 06:00 AM

Dude, do you ever sleep. HAHA. We swear you have a laptop with you 24/7 answering this forum. Thanks for the code, it does exactly what we wanted. You are the man!!

James Tran
Replied On September 20, 2004 02:22 PM

Clay, Can I get this code in C#? I am trying to find out which rows (0-n) are currently selected by the user via CTRL+Click. >If I understand what you want, I think you can do it by subscribing to the CellClick event. >
>Private Sub gridControl1_CellClick(sender As Object, e As GridCellClickEventArgs)
>   ''check for ctl+click
>   If(Control.ModifierKeys And Keys.Control) <> 0 Then
>      
>      Dim rangeList As GridRangeInfoList
>      If Me.gridControl1.Selections.GetSelectedRanges(rangeList, False) Then
>         Dim clickedCell As GridRangeInfo = Me.gridControl1.CurrentCell.RangeInfo
>         Dim clickedCellCol As GridRangeInfo = GridRangeInfo.Col(Me.gridControl1.CurrentCell.ColIndex)
>         Dim newCol As Boolean = True
>         Dim range As GridRangeInfo
>         For Each range In  rangeList
>            If range <> clickedCell And range.IntersectsWith(clickedCellCol) Then
>               newCol = False
>               Exit ForEach
>            End If
>         Next range
>         If newCol Then
>            Console.WriteLine("ctl+click into new column")
>         End If
>      End If
>   End If 
>End Sub ''gridControl1_CellClick
>

Administrator [Syncfusion]
Replied On September 20, 2004 06:09 PM

If you want to iterate through selected rows, you should look at this KB. http://www.syncfusion.com/Support/article.aspx?id=564 Here is the previous sample in C#. cellclick_5301.zip

Administrator [Syncfusion]
Replied On September 23, 2004 11:35 AM

Thanks...this will work. However, in my case, the first column is an identifier and is not clickable by the user. Since the row is not clickable, the SelectionChanged event never gets called. What I would like instead is if the user clicks on any cell (other than the cells in the first column which are not clickable), that is equivalent to selecting the whole row. Now, they would hold CTRL and click on a cell in another row. This action would result in the selection of two rows. How can I get a callback on this action and find out which two rows were selected?

Administrator [Syncfusion]
Replied On September 23, 2004 02:25 PM

Will setting the grid.ListBoxSelectionMode = SelectionMode.MultiExtended do what you want? It will select the whole row whenever you click in the row, and you can use ctl+Click to select additional rows.

Administrator [Syncfusion]
Replied On September 24, 2004 08:30 AM

Unfortnately, this did not work. I''m not getting the callback when I click on a row. I have attached the example project with a break point in the callback. Click on multiple rows and the callback will not get called. Thanks. >Will setting the grid.ListBoxSelectionMode = SelectionMode.MultiExtended do what you want? > >It will select the whole row whenever you click in the row, and you can use ctl+Click to select additional rows. CS_2203.zip

Administrator [Syncfusion]
Replied On September 24, 2004 11:30 AM

Hi Jane, I think you only need to add this line: gridControl1.SelectionChanged += new GridSelectionChangedEventHandler(gridControl1_SelectionChanged); Then you handler will be called. In the sample you sent the event handler was not wired up at all. Stefan

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.

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.

;