I have a grid with several columns, only the two right most columns are editable. When a user clicks on a cell that isn't editable, I want focus to go to the first cell on that row that is editable. Why doesn't the following code work? The selected cell stays on the cell clicked on.
Private Sub grdOptions_BeforeSelectChange(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeSelectChangeEventArgs) Handles grdOptions.BeforeSelectChange If e.NewSelections.Cells.Count = 0 Then Exit Sub If e.NewSelections.Cells(0).Column.CellActivation = Activation.AllowEdit Then Exit Sub e.Cancel = True For Each c As UltraGridCell In e.NewSelections.Cells(0).Row.Cells If c.Column.CellActivation = Activation.AllowEdit Then LogCommon.WriteDebug(New String() {"grdOptions_BeforeSelectChange()", "Select Changed To", c.Column.Header.Caption}) c.Selected = True Exit For End If Next End Sub
I figured out what I was trying to accomplish with the code below. It doesn't make sense why it works, but it works. If I have an editable cell that is currently in edit mode on row 3 and I use the mouse and click on a non-editable cell on row1, the first editable cell on row 1 is now my editable cell. And this works in the 'BeforeSelectChange' event using the 'PerformAction' command 'NextCellByTab'. If it's a bug, don't fix it.
Private Sub grdOptions_BeforeSelectChange(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeSelectChangeEventArgs) Handles grdOptions.BeforeSelectChange If e.NewSelections.Cells.Count = 0 Then Exit Sub Dim c As UltraGridCell = e.NewSelections.Cells(0) If e.NewSelections.Cells(0).Column.CellActivation = Activation.AllowEdit Then Exit Sub e.Cancel = True grdOptions.PerformAction(UltraGridAction.NextCellByTab, False, False) Exit Sub
To answer your question from above, during 'InitializeLayout' I am settings c.CellActivation to either Activation.NoEdit or Activation.AllowEdit.
How are you disabled editing in the other columns? From the code here, it seems like you are probably setting CellActivation on the columns, but what are you setting it to? If it's Disabled, then I expect BeforeSelectChange will not even fire when you click on one of those cells.
Also, it seems to me like you should be concerned with the active cell here, not selected. Active and selected are two totally different things and it's important to understand the different. A grid can have multiple selected cells - this just means that the cell is highlighted to the user. There can only be only active cell - this is the cell that is being edited.
But again, if the CellActivation is disabled, the BeforeCellActivate event won't even fire when you click on that cell.