winform中如何选中datagridview中的一行数据双击后跳转并将其显示在另一个页面的datagirdview中

显示在另一个页面的datagridview中
2024年10月31日 21:42
有1个网友回答
网友(1):

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
        }