Default forced button for gridview

I use gridview with templates to display and edit some information from sql database.

When I edit and modify the data in this row and then press the "Enter" button, it automatically presses the highest button on the page, which uses the value "true" to send to the server, which means that it will try to delete instead of updating.

I tried to set the panel around the gridview and set the default panel button to the "updatebutton" button, but it will not allow this because it cannot see the button.

+3
source share
2 answers

, :

  • GridView CSS (, position: relative; left: -2000px)
  • GridView DefaultButton .
  • : myGridView.UpdateRow(myGridView.EditIndex, false);

, Enter GridView, .

+3

KeyDown KeyPress , , Keys.Enter:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            button1_Click(this, EventArgs.Empty);
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        // Your logic here
    }
}
0

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


All Articles