问题描述
由于某些奇怪的原因,当我选中或取消选中数据网格中的复选框时,无论值
For some odd reason when I check or uncheck the checkbox in the data grid, I still recieved true no matter what for the value
哪个不正确,我仍然收到了真的。如果取消选中该复选框,则该值假定为false。如果选中该复选框,则该值为true。有人可以帮助我解决这个问题。提前致谢。
which is incorrect. If the checkbox is uncheck, the value is suppose to report false. If the checkbox is checked the value is suppose to be true. Can someone assist me with this issue. Thanks in advance.
private void dataGridView1_CellClick(object sender,DataGridViewCellEventArgs e)
      {
$
          if(e.RowIndex> = 0)
          {
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
              DataGridViewRow row = this.dataGridView1.Rows [e.RowIndex];
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
        }
}
}
pianoboyCoder
pianoboyCoder
推荐答案
using System;
using System.Windows.Forms;
namespace SuppressEnter
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
dataGridView1.CellContentClick += DataGridView1_CellContentClick;
}
private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
var senderGrid = (DataGridView)sender;
senderGrid.EndEdit();
if (e.RowIndex >= 0)
{
var cbxCell = (DataGridViewCheckBoxCell)senderGrid.Rows[e.RowIndex].Cells["processColumn"];
if ((bool)cbxCell.Value)
{
Console.WriteLine("Checked");
}
else
{
Console.WriteLine("Unchecked");
}
}
}
private void Form2_Load(object sender, EventArgs e)
{
dataGridView1.Rows.Add(new object[] { true, "A" });
dataGridView1.Rows.Add(new object[] { true, "B" });
dataGridView1.Rows.Add(new object[] { false, "C" });
dataGridView1.Rows.Add(new object[] { true, "D" });
}
}
}
这篇关于Datagrid查看单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!