在c#的winform中的datagrid中有一列为DataGridBoolColumn(有"√")类型,当双击此列时,它的checked可改变(没有"√"),当当双击另一行的此列时,它又恢复原样(有"√"),应如何实现双击此列后没有"√"的变为有"√",有"√"的变为有"√"?
DataGridBoolColumn boolCol= new DataGridBoolColumn();
boolCol.MappingName = "cxz2";
boolCol.HeaderText = "选择2";
boolCol.Width = 50;
boolCol.AllowNull=false;
boolCol.NullValue=false;
boolCol.FalseValue=false;
boolCol.TrueValue=true;
//添加事件处理器
// boolCol.FalseChanged +=new EventHandler(boolCol_FalseChanged);
// boolCol.TrueValueChanged +=new EventHandler(boolCol_TrueValueChanged); ts1.GridColumnStyles.Add(boolCol); dataGrid1.TableStyles.Add(ts1);
DataGridBoolColumn boolCol= new DataGridBoolColumn();
boolCol.MappingName = "cxz2";
boolCol.HeaderText = "选择2";
boolCol.Width = 50;
boolCol.AllowNull=false;
boolCol.NullValue=false;
boolCol.FalseValue=false;
boolCol.TrueValue=true;
//添加事件处理器
// boolCol.FalseChanged +=new EventHandler(boolCol_FalseChanged);
// boolCol.TrueValueChanged +=new EventHandler(boolCol_TrueValueChanged); ts1.GridColumnStyles.Add(boolCol); dataGrid1.TableStyles.Add(ts1);
解决方案 »
- SQL中能用,C#中不能用的SQL~~~
- 初学者关于Main()定义的疑问
- -----------winform 中treeView,和DataGridView的连动问题??
- 请问
- Duwamish 7.0问题,请高手帮忙解惑
- 如何实现主线程和子线程序之间的通讯问题????
- 请教一个关于拨号连接的问题
- c#怎么统计用户信息
- 求一个简单的直线公式?
- c#画图问题求救
- 为什么DataGrid中的DataGridBoolColumn的"TrueValueChanged()"和"FalseValueChanged"和"AllowNullChanged"事件无法响应?--- 求助DataGri
- 在winform中怎么连接数据库并用datagrid显示?
源码下载:在DataGridColumnStyle的单元格中使用DateTimePicker、ComboBox、NumericUpDown等控件
http://community.csdn.net/Expert/topic/3522/3522038.xml?temp=.2270777
/// 对DataGrid中的CheckBox进行值判断,并对数据库做出修改
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dataSource_CurrentCellChanged(object sender, System.EventArgs e)
{
try
{
string temp = dataGridView[Convert.ToInt32(dataGridView.CurrentCell.RowNumber),0].ToString();
this.dataGridView.Select(dataGridView.CurrentCell.RowNumber);
DataAccess data = new DataAccess();
//判断是否点中的是CheckBox列,以保证其值正确更改
if(dataGridView.CurrentCell.ColumnNumber == 12)
{
//判断CheckBox单元格的值,并根据其值更新数据库
if(dataGridView[Convert.ToInt32(dataGridView.CurrentCell.RowNumber),12].ToString() == "False")
{
dataGridView[Convert.ToInt32(dataGridView.CurrentCell.RowNumber),12] = true;
string query_sql = "update accounttype set accflag = '1' where id = '" + temp + "'";
data.ExecuteSQL(query_sql);
}
else if(dataGridView[Convert.ToInt32(dataGridView.CurrentCell.RowNumber),12].ToString() == "True")
{
dataGridView[Convert.ToInt32(dataGridView.CurrentCell.RowNumber),12] = false;
string query_sql = "update accounttype set accflag = '0' where id = '" + temp + "'";
data.ExecuteSQL(query_sql);
}
}
else
{
//选中的不是CheckBox列就跳出此过程
return;
}
}
catch
{
MessageBox.Show("表格中未有任何记录!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
} }