I have an UltraGrid control on a form, and the form has a context menu which the grid references as its context menu strip. When you invoke the context menu (right-click), I've noticed the underlying row (I have full row selection enabled) does not become selected and/or focused. So, I added the event handler below to try to accomplish this. When I left-click a row and then right click another row, there are two rows selected. My grid is set only to have one selected row at a time, but for some reason when the event fires, it still results in multiple rows being selected. The message box is in place to demonstrate that the program thinks there is only one row selected, but the UI shows two rows. Is there something I'm doing wrong?
Private Sub LogDataUltraGrid_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LogDataUltraGrid.MouseDown 'get the cell that was clicked.. Dim objCell As UltraGridCell = _ Me.LogDataUltraGrid.DisplayLayout.UIElement.LastElementEntered.GetContext(GetType(UltraGridCell)) If Not objCell Is Nothing Then 'remove the previous selection if there was one... If Me.LogDataUltraGrid.Selected.Rows.Count > 0 Then Me.LogDataUltraGrid.Selected.Rows(0).Selected = False objCell.Row.Selected = True MsgBox(Me.LogDataUltraGrid.Selected.Rows.Count) End If End Sub
Hi,
There aren't two rows selected. The row you left-clicked on is active and so it appears like it is selected.
FAQ:How do I turn off the ActiveRowAppearance so that the active row in the grid does not appear selected.
Rory,
Yes, I am sending you a sample application which uses the code that you have in your MouseDown event and I think you will see what is going on. You need to Active the object that you clicked over and because SelectTypeRow is set to Single you don't need to "deselect" the previously selected row.
Check out the sample and let me know if you have further questions.
Michael S.
Michael,
Thank you for your reply. I was able to use the suggestion of Mike Saltzman to figure out what I was doing wrong, so I did not get a chance to look at the sample you sent me. You may close the issue.
-Rory
Did the sample I sent you help you to straighten out the issues you were having with selecting and activating rows? If you do not require further assistance with this case may I close it? You can open it again if you need to within 30 days of its closure and you can always open a new case at any time.
Thank you for using Infragistics.