gridview中的DataGridViewCheckBoxColumn

时间:2013-04-03 15:35:25

标签: c# datagridview

请检查代码

studentlistGridView.DataSource = null;

AFTER THAT

CONNECTION CODE AND RETRIEVE ALL THE RECORDS FROM 
dB TABLE <br />
-----------------------AFTER THAT-------------------
<br /><br /><br />
checkstudent = new DataGridViewCheckBoxColumn();<br />
checkstudent.Selected = false;<br />
checkstudent.HeaderText = "SELECT STUDENT";<br />
checkstudent.Width = 130;<br />
checkstudent.Name = "chkbox";<br />
checkstudent.ToolTipText = ds.Tables["Students"].Rows[0][1].ToString();<br />
studentlistGridView.Columns.Add(checkstudent);<br />
<br /><br />

点击刷新按钮WITH NEW ID AS PARAMETER时遇到问题 最后一个gridview的复选框出现在报告的开头并且来了 在多列中。请指出我正确的方法

1 个答案:

答案 0 :(得分:0)

假设这在WinForms DataGridView中,那么看起来好像你需要在添加之前检查列:

// If the column isn't in the Columns collection...
if (!studentlistGridView.Columns.Contains("chkbox"))
{
    // Add column
}

这使用了采用列名的Contains方法:

http://msdn.microsoft.com/en-us/library/bkkh95eb.aspx