WinForm How to select a row of data in DataGridView double-click to jump and display it in the Datagirdview of another page

Source: Internet
Author: User
Tags rowcount

Form1:

    public static string [] a;    private void dataGridView1_DoubleClick( object sender, EventArgs e) //添加datagridview1的双击事件          {              try              {                  int index = dataGridView1.CurrentRow.Index;                  a =  new string [dataGridView1.ColumnCount];                  for ( int i = 0; i < dataGridView1.ColumnCount; i++)                  {                      a[i] = dataGridView1.Rows[index].Cells[i].Value.ToString();                   }                  Form2 f2 =  new Form2();                  f2.Show();                                                                                     }              catch { }          } Form2: //    public Form2()          {              InitializeComponent();              showGridView();          }    private void showGridView()          {              DataGridTextBoxColumn tb =  new DataGridTextBoxColumn();              dataGridView1.Rows.Add(tb);              for ( int i = 0; i < dataGridView1.ColumnCount;i++ )                  dataGridView1.Rows[dataGridView1.RowCount-2].Cells[i].Value = Form1.a[i]; //根据AllowUserToAddRow属性选择最后一行,true时dataGridView1.RowCount-2,false时dataGridView1.RowCount-1          }

WinForm How to select a row of data in DataGridView double-click to jump and display it in the Datagirdview of another page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.