使DatagridView行变为不可选择 [英] Make DatagridView Rows unselectable
本文介绍了使DatagridView行变为不可选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个3行的DataGridView.
我正在以编程方式添加第四行.
添加第四行后,有什么方法可以防止用户选择三行.
谢谢大家
:)
I have a DataGridView with 3 rows.
I am adding a fourth row programmatically.
Is there any way to prevent the user from selecting the three rows after I add the fourth row.
Thanks a ton everyone
:)
推荐答案
嗨
我对我们的问题不是很清楚,但是逻辑是这样的:
Hi
I am not cleared about our question very much but the logic is something like:
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
//If Rows > 3 then it will not display selected row (from 1 to 3 rows)
if (GridView1.Rows.Count > 3)
{
if (e.NewSelectedIndex > 2)
{
//If Rows > 3 and SelectedIndex > 2 (it started from 0) then it will display selected row (from 4 to n..)
GridView1.Rows[e.NewSelectedIndex].CssClass = "AllowSelection";
}
else
{
//If Rows > 3 and SelectedIndex < 2 (it started from 0) then it will not display selected row (0 to 2)
GridView1.Rows[e.NewSelectedIndex].CssClass = "DisallowedSelection";
}
}
else
{
//If Rows < 3 then it will display selected row (0 to 2)
GridView1.Rows[e.NewSelectedIndex].CssClass = "AllowSelection";
}
}
如有任何疑问,请让我知道.
如果对您有帮助,请提供投票.
谢谢,
Imdadhusen
Please do let me know, if you have any doubt.
Please provide Vote if this would be helpful to you.
Thanks,
Imdadhusen
这篇关于使DatagridView行变为不可选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文