[英]How to untick check box value
I'm using WinForms Data Grid . 我正在使用WinForms数据网格 。 There is a column for checkboxes.
有一个复选框栏。 When the user checks once and try to not checking again there will be a message box is asking,
当用户检查一次并尝试不再次检查时,将出现一个消息框,
Already exists!
已经存在! \\nDo you want to change?
\\ n您要更改吗?
. 。 When user click YES previous checkbox will uncheck the and new one will be checked.
当用户单击“是”时,上一个复选框将取消选中,然后将选中新的复选框。 But if user click NO both will be checked.
但是,如果用户单击“ 否” ,则将两者都选中。 I want to uncheck new one when user click NO .
当用户单击“ 否”时,我想取消选中新的 。
private void dgTeam1_CellClick(object sender, DataGridViewCellEventArgs e)
{
int pIndex = _list1.playerList.FindIndex(p => p.captain == true);
if (e.ColumnIndex == 6)
{
if (pIndex != -1)
{
DialogResult result = MessageBox.Show("Captain already exists! \nDo you want change?", "Change Captain Confirmation", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
dgTeam1[6, pIndex].Value = false;
else
{
dgTeam1[6, e.RowIndex].Value = false;
}
}
}
}
I don't know what's the rest of your code, so I consider that code until your MessageBox works properly as it should. 我不知道剩下的代码是什么,因此我会考虑该代码,直到您的MessageBox正常工作为止。 You were not that far, you have to use a string and instead of a boolean :
您还不算太远,必须使用字符串而不是布尔值:
private void dgTeam1_CellClick(object sender, DataGridViewCellEventArgs e)
{
int pIndex = _list1.playerList.FindIndex(p => p.captain == true);
if (e.ColumnIndex == 6)
{
if (pIndex != -1)
{
DialogResult result = MessageBox.Show("Captain already exists! \nDo you want change?", "Change Captain Confirmation", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
dgTeam1[6, pIndex].Value = "false";
}
else
{
dgTeam1[6, e.RowIndex].Value = "false";
}
}
}
}
As I said before, I don't really know how works your codes elsewhere of this part, so you may have to arrange it a bit to fit to your needs. 就像我之前说过的,我真的不知道您的代码在本部分其他地方的工作方式,因此您可能需要对其进行一些调整以满足您的需求。
you may want to try something like this, first declare the checkbox cell in a variable, then set the value to null 您可能想要尝试这样的操作,首先在变量中声明复选框单元格,然后将值设置为null
foreach (DataGridViewRow row in UrDGV.Rows)
{
DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)row.Cells["ChkBoxCol"];
if (ischecked == true)
{
chk.Value = null;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.