datagridviewcell中的错误使用csharp更改了事件 [英] Error in datagridviewcell changed event using csharp
问题描述
注意它是windows应用程序。
i有一个datagridview,在datagridview中我有两个复选框。
两个复选框名称如下;
第一个复选框列名称checkboxselect
标题文本日
第二个复选框列名称sess1
标题文本会话
在datagridview中以上两个复选框将在那里。
i当我点击第一个复选框时,我想要在datagridview中选中第二个复选框
类似地,当我复制第二个复选框以取消选中第一个复选框以在数据网格视图中取消选中。
为此我在datagridview中编写了一个代码CellValueChanged。
我的代码如下;
private void DGVCalendar_CellValueChanged(object sender,DataGridViewCellEventArgs e)
{
if(DGVCalendar.Columns [e.ColumnIndex] .Name ==checkboxselect&& DGVCalendar.CurrentCell is DataGridViewCheckBoxColumn)
bool ischecked =(bool)DGVCalendar [e.ColumnIndex,e.RowIndex] .EditedFormattedValue;
if(ischecked == true)
{
DGVCalendar.Columns [3] .Name = false;
}
}
来自我的代码checkboxselect是firstcheckbox,我提到列(3)是第二个复选框。
i写在上面代码,当我点击第一个复选框,我想要第二个复选框取消选中。
该怎么做?
$ b从我的代码$ b我犯了什么错误
当我运行上面的代码错误如下;
嵌入式语句不能是声明或标记为sta tement
请帮帮我
问候,
Narasiman p。
请注意它是Windows应用程序。
note it is windows application.
i have one datagridview, in that datagridview i have two checkboxes.
Two checkbox name as follows;
First checkbox column name checkboxselect
Header text Day
Second checkbox column name sess1
Header text session
inside the datagridview the above two check boxes will be there.
i want when i click the first checkbox checked, i want second checkbox to checked in datagridview
similarily when i clcik the second checkbox to unchecked first checkbox to be uncheckedin datagridview.
for that i written a code in datagridview CellValueChanged.
my code as follows;
private void DGVCalendar_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if(DGVCalendar.Columns[e.ColumnIndex].Name == "checkboxselect" && DGVCalendar.CurrentCell is DataGridViewCheckBoxColumn)
bool ischecked = (bool)DGVCalendar[e.ColumnIndex,e.RowIndex].EditedFormattedValue;
if(ischecked == true)
{
DGVCalendar.Columns[3].Name = false;
}
}
from my code checkboxselect is the firstcheckbox and i mention the column(3) is the second checkbox.
i written a above code when i click the first checkbox i want second checkbox to unchecked.
for that how to do?
from my code what is the mistake i made
when i run the above code error as follows;
Embedded statement cannot be a declaration or labeled statement
please help me
regards,
Narasiman p.
note it is windows application.
推荐答案
private void DGVCalendar_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
try
{
DataGridView dgv = (DataGridView)sender;
DataGridViewCell cell = dgv.CurrentCell;
if (cell.RowIndex > -1 && (cell.ColumnIndex == 1 || cell.ColumnIndex == 2))
{
if (cell.ColumnIndex == 1)
{
DGVCalendar.Rows[cell.RowIndex].Cells[1].Value = true;
DGVCalendar.Rows[cell.RowIndex].Cells[2].Value = false;
}
else
{
DGVCalendar.Rows[cell.RowIndex].Cells[2].Value = true;
DGVCalendar.Rows[cell.RowIndex].Cells[1].Value = false;
}
}
}
catch (Exception exc)
{
exc.ToString();
}
}
这篇关于datagridviewcell中的错误使用csharp更改了事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!