winForm 下的dataGrid中复选框,为什么得点两下鼠标才能选中?点第一次为选中单元格,点第二次才行 winForm 下的dataGrid中复选框,为什么得点两下鼠标才能选中?点第一次为选中单元格,点第二次才能打上钩或去掉钩。有没有办法能点一次就能行? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 写代码在相应的嵌入的checkbox的mousedown,记录鼠标点击次数,然后改变相应的值。 tryhttp://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp 都是高人回答的我就不说话了.应该重载mouserdown事件。一次完成两件事。 除非你只要点复选框,否则当你重载了Mousedown后,要想做其它事就麻烦了所以点两次又何妨? 源码下载:在DataGridColumnStyle的单元格中使用DateTimePicker、ComboBox、NumericUpDown等控件http://community.csdn.net/Expert/topic/3522/3522038.xml?temp=.2270777 /// <summary> /// 对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); } } 我要试验仪下上传图片先 关于继承webservice 的问题 vb中debug.print在C# 中用什么代替? ftp下载文件 如何在文件的特定位置写一句话 我在看DirectX9 的例的时候,源程序不能正常运行,提示TextureState,Sampler没有引用.我找遍了也没找到它们是哪个命名空间下的类.谁知道啊? C#安装 oracle简单问题 我的if语句为什么不执行呢? 那里能下载到VS.NET的正式版本,最好是5CD的 美国CNN新闻上正在网上做日本否应该加入常任理事国调查,朋友们去投票! Attributes是干什么用的?求详解
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
我就不说话了.
应该重载mouserdown事件。
一次完成两件事。
所以点两次又何妨?
源码下载:在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);
} }