Windows应用程序中的DataGridview

问题描述:





我在数据库中有一个表部门(DeptID,DeptName,Location)。



需要将数据导入datagridview,其中第一列必须是复选框,最后一列必须是删除按钮。



1)如何执行此操作...我没有想到,因为我从未在Windows应用程序中尝试过。

2)如果选中复选框并单击删除按钮,如何选择行。



谢谢..



Prathap

Hi,

I have a table Department (DeptID,DeptName,Location) in database.

Need to get data into datagridview where the first column must be a Checkbox and last column must be a delete button.

1) How to do this...I am not getting any idea as I have never tried in Windows app.
2) How to select a row when checkbox is selected and Delete button is clicked.

Thank you..

Prathap

DataGridView控件及其相关类被设计成一个灵活,可扩展的系统,用于显示和编辑表格数据。 DataGridView控件提供TextBox,CheckBox,Image,Button,ComboBox和Link列以及相应的单元格类型。在单元格中添加CheckBox时,可以通过程序代码显式设置单元格Value属性,该代码访问行的Cells集合中的单元格,也可以通过数据绑定进行设置。



以下C#代码显示如何在DataGridView控件的Cell中添加CheckBox,并将第三行复选框值设置为true。

The DataGridView control and its related classes are designed to be a flexible, extensible system for displaying and editing tabular data. The DataGridView control provides TextBox, CheckBox, Image, Button, ComboBox and Link columns with the corresponding cell types. While adding a CheckBox in a cell, the cell Value property can be set explicitly through programmatic code that accesses the cell in the Cells collection of the row, or it can be set through data binding.

The following C# code shows how to add a CheckBox in Cell of a DataGridView control and set the third row checkbox value as true.
DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn();
dataGridView1.Columns.Add(chk);
chk.HeaderText = "Check Data";
chk.Name = "chk";
dataGridView1.Rows[2].Cells[3].Value = true;





这显示了如何添加按钮;



And this shows how to add a button;

DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
dataGridView1.Columns.Add(btn);
btn.HeaderText = "Click Data";
btn.Text = "Click Here";
btn.Name = "btn";
btn.UseColumnTextForButtonValue = true;





祝你好运,

OI



Good luck,
OI


这些是给你的..

http://www.dotnetspider.com/resources/43689-How-create-check-box-column-datagridview.aspx [ ^ ]

http://csharp.net-informations.com/datagridview /csharp-datagridview-button.htm [ ^ ]
These are for you..
http://www.dotnetspider.com/resources/43689-How-create-check-box-column-datagridview.aspx[^]
http://csharp.net-informations.com/datagridview/csharp-datagridview-button.htm[^]


http://msdn.microsoft.com/ en-us / library / system.windows.forms.datagridviewbuttoncolumn.aspx [ ^ ]

http://social.msdn.microsoft.com/Forums/hr/winformsdatacontrols/thread/a8160578-baa4-4c2b-beb6-d44cbfb7fe2d [ ^ ]



和解决方案#1和#2也很好......祝你好运:)
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewbuttoncolumn.aspx[^]
http://social.msdn.microsoft.com/Forums/hr/winformsdatacontrols/thread/a8160578-baa4-4c2b-beb6-d44cbfb7fe2d[^]

and solution #1 and #2 is good as well... Good Luck :)