如何在C#窗体中控制数据网格视图中的行数 [英] How to control the amount of rows in a datagridview in C# windows form
本文介绍了如何在C#窗体中控制数据网格视图中的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
美好的一天请我有一个datagridview,我使用它一次输入4个信息,但不希望datagridview超过4行(我不希望用户一次输入超过4行)。如果行是超过四个datagridview不应再延长
我尝试过:
Good day Please i have a datagridview and i use it enter 4 informations at once but dont want the datagridview to exceed more than 4 rows (i dont want the user to enter more than 4 rows at once).If the rows are more than four the datagridview should not extend any longer
What I have tried:
if (dataGridView1.Rows.Count >= 4)
{
MessageBox.Show("you cant exceed this number");
}
推荐答案
使用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;
}
}
这篇关于如何在C#窗体中控制数据网格视图中的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文