Click here to Skip to main content
16,016,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have datagrid with addnew button and delete button columns.
when i click on add new button the focus should come on the new row.
What should i do?


Now i have added two events
C#
private void DataGrid_CurrentCellChanged(object sender, EventArgs e)
        {
            DataGrid.BeginEdit();
        }

private void DataGrid_PreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e)
        {
                UIElement inputElement;
                inputElement = DataGridHelper.GetVisualChild<TextBox>(e.EditingElement);
                if (inputElement != null)
                {
                    Keyboard.Focus(inputElement);
                }
        }




But Now i have to click twice the AddNewButton for a new row to come or for deleting i have click twice the delete button.

To Solve this what should i do?
Please help me!
Posted

1 solution

You are confused probably because you are trying to find how to "focus", but this notion is not applicable to cells. "Focus" always mean "keyboard focus" and is only applicable to the whole control.

For a cell or a row, you need to apply "selection". Just select one of the cells:
http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.currentcell.aspx[^].

The result of it depends on selection mode.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900