Reputation: 246
Hi
I have a DataGridView which is bound to an XML source.
How can I achieve this?
Upvotes: 5
Views: 10705
Reputation: 978
If I understand you correctly you want the cell to enter edit mode as soon as it is clicked. This can be achieved by setting the EditMode
property of the DataGridView to EditOnEnter
.
This leaves the text in the editing control selected however, so if you don't want that you could use:
dataGridView1_CurrentCellChanged(object sender, EventArgs e)
{
dataGridView1.BeginEdit(false);
}
Can you explain what you mean by adding row dynamically?
Upvotes: 4
Reputation: 834
With respect to question 1)
You can try this:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
this.dataGridView1.CellEnter += new DataGridViewCellEventHandler(myDataGrid_CellEnter);
}
void myDataGrid_CellEnter(object sender, DataGridViewCellEventArgs e)
{
if ((this.dataGridView1.Columns[e.ColumnIndex] is DataGridViewTextBoxColumn) ||
(this.dataGridView1.Columns[e.ColumnIndex] is DataGridViewComboBoxColumn))
{
this.dataGridView1.BeginEdit(false);
}
}
Upvotes: 3