UltraWinGrid enter edit mode issue

2019-08-04 13:33发布

问题:

I have an UltraWinGrid and I want to give the focus to a specific cell and make it enter edit mode programmatically (no click). So I did this :

If myUltraWinGrid.ActiveRow IsNot Nothing Then
myUltraWinGrid.ActiveCell = myUltraWinGrid.ActiveRow.Cells("foo")
myUltraWinGrid.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditMode)
Else
myUltraWinGrid.ActiveCell = myUltraWinGrid.Rows(0).Cells("foo")
myUltraWinGrid.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditMode)
EndIf

Which should work but it only gives focus to the row (no edit mode).

fooColumn   
   |
  \_/

回答1:

I don't know why but calling it with BeginInvoke solved the issue.

BeginInvoke(New MethodInvoker(AdressOf SetFocusToRow))

Private sub SetFocusToRow()
{
  myUltraWinGrid.ActiveCell = myUltraWinGrid.ActiveRow.Cells("foo")
  myUltraWinGrid.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditMode)
}


回答2:

Because it's executed by another thread by some reason

myUltraWinGrid.BeginInvoke(new MethodInvoker(()=> myUltraWinGrid.PerformAction(UltraGridAction.EnterEditMode)));