日期:2014-05-17  浏览次数:20933 次

晕了,撞鬼了。。。C#2012 DataGridView 出怪事? 不能做全选付值。。。。。
本帖最后由 keith_cheung 于 2013-03-25 23:41:55 编辑


如上图,在 DataGridView 中,本想做一个弹出菜单,来进行全选。
其它的项都可以付值为 true, 就是有蓝色框框的一个,死活付不了值。
(无论鼠标是否指正蓝色框框。)
但同样的代码,我另建一个 button ,用它来进行全选,又是可行的。

请问这是怎么回事???难道是弹出的菜单,另有。。。???

搞不明白!请大家指点一二,谢谢了!

------------------------------------------------------

for (int i = 0; i < dataGridView8.Rows.Count - 1; i++)
{
   dataGridView8[0, i].Value = true;
//或用 dataGridView8.Rows[i].Cells[0].Value = true; 也不行
}
DataGridView C#

------解决方案--------------------

for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
            {
                dataGridView1[0, i].Value = true;
                //或用 dataGridView8.Rows[i].Cells[0].Value = true; 也不行
            }
            dataGridView1.CurrentCell = null;
            dataGridView1.Rows[0].Selected = false;

------解决方案--------------------
dataGridView1.CurrentCell = null;
就能达到你要的效果;
            
//dataGridView1.Rows[0].Selected = false;用来选择你想选择的项
------解决方案--------------------
dataGridView1.CurrentCell = null;

------解决方案--------------------
dataGridView8.BeginEdit();
for (int i = 0; i < dataGridView8.Rows.Count - 1; i++)
{
   dataGridView8[0, i].Value = true;
//或用 dataGridView8.Rows[i].Cells[0].Value = true; 也不行


dataGridView8.EndEdit();

手动提交下。。。
------解决方案--------------------
i<=dataGridView8.Rows.Count-1;
i<dataGridView8.Rows.Count;
for (int i = 0; i < dataGridView8.Rows.Count; i++)

你也可以这样
foreach (DataGridViewRow row in dataGridView8.Rows){
  row.Cells[0].Value =...
}
------解决方案--------------------
private void 已发布ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dataGridView_user.Rows.Count; i++)
            {
                if (dataGridView_user.Rows[i].Cells[3].Value.ToString() == "已发布")
                    dataGridView_user.Rows[i].Cells[0].Value =&nb