Pergunta

I am using the devexpress TreeList control. In Treelist I have a situation where one of my column is read only. This column may have some text values added when something happens in another cell. I have restricted user entry in the cell by setting a property like this

    treeList1.Columns["col3"].OptionsColumn.ReadOnly = true;

Now I want to remove text value from some of the cells and since it is read only the delete buttons does not work. Can you suggest the event/method and the code which will allow user to delete the text? Any help would be much appreciated.

Foi útil?

Solução

Edited solution :

You should know that when the cursor is in the cell (in edit mode), and you press a button, it's not the TreeList who send the KeyDown event, but the RepositoryItemButtonEdit. So, you should handle the event also for the RepositoryItemButtonEdit.

To not duplicate code, I've wrote one handler 'onKeyDown', in whitch I verify who is the sender.

treeList1.KeyDown += onKeyDown;
riButtonEdit.KeyDown += onKeyDown;

And here is a code exemple showing you how to handle the KeyDown event for both treeList and repositoryButtonEdit, and set the cell value to null :

private void onKeyDown(object sender, KeyEventArgs e)
{
    // Test if the button pressed is the delete button
    if (e.KeyCode != Keys.Delete)
        return;

    // Test if the focused column is colValue
    if (treeList1.FocusedColumn != colValue)
        return;

    // Set the cell value to null
    treeList1.FocusedNode.SetValue(colValue, null);

    // If it's the ButtonEdit who send the event, make it's EditValue null
    var btnEdit = sender as ButtonEdit;
    if (btnEdit != null)
    {
        btnEdit.EditValue = null;
    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top