Editing DataGridView Cells

Hello
I have a DataGridView that is linked to an XML source.

  • I have a problem editing cells. The cell on the click becomes selected, and when it is edited, by default we overwrite it. My requirement says that it should be ready for editing and not selected when clicked.
  • I want to generate a line dynamically whenever the tab key is pressed.

How can i achieve this?

+4
source share
2 answers

Regarding Question 1)

You can try the following:

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); } } 
+2
source

If you correctly understood that the cell should enter the editing mode as soon as it is pressed. This can be achieved by setting the EditMode DataGridView property to EditOnEnter . However, this leaves the text in the edit control, so if you do not want you to be able to use:

 dataGridView1_CurrentCellChanged(object sender, EventArgs e) { dataGridView1.BeginEdit(false); } 

Can you explain what you mean by adding a line dynamically?

+2
source

Source: https://habr.com/ru/post/1340802/


All Articles