简体   繁体   中英

DataGridView Cell Editing

Hi
I have a DataGridView which is bound to an XML source.

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM