Hi
I have a DataGridView which is bound to an XML source.
How can I achieve this?
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?
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);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.