Search code examples
c#winformsobjectlistview

Trigger the ObjectListView cell into editing status from outside


We have a win form, there is an ObjectListView and a button named btnOK on the form. Normally, I can edit a cell by click on the cell in the ObjectListView but I want the specify cell go into the editing status (a TextBox in the cell and focus on it) by clicking the btnOK.

It seems that ObjectListView does not support it, as the CellEventArgs only provide the properties which support "get" method only, but not provide "set" method.

Is there any possible or any other way to implement my requirement?


Solution

  • It seems that ObjectListView does not support it, as the CellEventArgs only provide the properties which support "get" method only, but not provide "set" method.

    Because CellEventArgs contains arguments for an ObjectListView event (for example CellEditFinishing), triggered in response to something that did happen. What you need to do is to programmatically start something that will happen.

    But I want the specify cell go into the editing status (a textbox in the cell and focuse on it) by click the btnOK.

    Simply call ObjectListView.EditSubItem() method. First parameter is a reference to list item you want to edit and second parameter which sub-item (column...) you want to edit. For example to start editing currently focused item:

    ctrlList.EditSubItem((OLVListItem)ctrlList.FocusedItem, 0);