且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C#窗体中控制数据网格视图中的行数

更新时间:2023-10-19 21:16:16

使用DataGridView.UserAddedRow Event(System.Windows.Forms) [ ^ ]



use DataGridView.UserAddedRow Event (System.Windows.Forms)[^]

private void dataGridView1_UserAddedRow(object sender, DataGridViewRowEventArgs e)
       {
           if (dataGridView1.Rows.Count > 4)
           {
               dataGridView1.AllowUserToAddRows = false;
               MessageBox.Show("you cant exceed this number");
           }
           else
           {
               dataGridView1.AllowUserToAddRows = true;

           }

       }