C#中带有复选框的Datagridview [英] Datagridview with checkbox in c#
问题描述
我有一个表,其中包含(Sno,Name,Cost,No_Of_Items)字段.
当我想通过复选框将此表绑定到DataGridview时.在底部,我有1个添加按钮和Textbox .....
我将在gridview中检查一些字段,然后单击添加"按钮,现在我希望所选项目的总成本将显示在文本框中....
I have a table with the fields like (Sno, Name, Cost, No_Of_Items).
when I want to bind this table into DataGridview with checkbox. In the bottom I have 1 add button and Textbox.....
I will checked some fields in gridview and click on add button, now I want total amount of selected items cost will appear in textbox....
推荐答案
这将有所帮助你
http://stackoverflow.com/questions/1074378/c-sharp- datagridview-checkbox-checked-event-multiple-rows [ ^ ]
http ://tech.chitgoks.com/2008/11/17/c-add-select-all-deselect-all-checkbox-in-column-header-in-datagridview-control/ [ ^ ]
This Will Help You
http://stackoverflow.com/questions/1074378/c-sharp-datagridview-checkbox-checked-event-multiple-rows[^]
http://tech.chitgoks.com/2008/11/17/c-add-select-all-deselect-all-checkbox-in-column-header-in-datagridview-control/[^]
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[1].Value != null && (bool)row.Cells[1].FormattedValue)
{
DialogResult dlgRes;
string teststr = "Are you want to delete";
dlgRes = MessageBox.Show(teststr, "Confirm Document Close", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dlgRes == DialogResult.Yes)
{
int idtoselect = (int)row.Cells[0].Value;
String str1 = idtoselect.ToString();
string constr = "DELETE FROM Member Where ID_Member =" + str1 + "";
SqlCommand cmd = new SqlCommand(constr, conn);
cmd.ExecuteNonQuery();
ds.Tables["Member"].Clear();
da.Fill(ds, "Member");
dataGridView1.DataSource = ds.Tables["Member"];
}
else
{
ds.Tables["Member"].Clear();
da.Fill(ds, "Member");
dataGridView1.DataSource = ds.Tables["Member"];
}
}
}
这是我的代码,以删除由datagridview行单元格1中的复选框和复选框选择的记录
并且id是datagridview行单元格0
希望您带上我的代码来解决您的问题
this''s my code to delete record that choose by checkbox and checkbox in datagridview Row cell 1
and id is datagridview Row cell 0
Hope you bring my code to apply for your question
感谢您的帮助aniketyadav7和pongpanut....我得到了解决方案....
Thanks for your help aniketyadav7 and pongpanut.... I got solution ....
这篇关于C#中带有复选框的Datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!