【发布时间】:2017-03-06 22:42:47
【问题描述】:
我正在制作 Windows 应用程序
我添加了 1 个按钮和 1 个数据网格视图。
当点击按钮时,数据显示在 DB 中的 datagridview 中。
还有这一步,我有个问题。
我想像这样以编程方式定义 DataGridView 列
- 第一列 = 复选框列
- 第二列 = 进程列(我要在这里绑定数据)
- 第三列 = 进度条列(我会制作此列)
SQL 查询如下
SELECT COUNT(*) as Process from Sales.SalesOrderDetail
UNION
SELECT COUNT(*) as Process from Purchasing.ProductVendor
UNION
SELECT COUNT(*) as Process from Person.Address
UNION
SELECT COUNT(*) as Process from Production.WorkOrder
而按钮点击事件是这样的
private void btnStart_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["AdvConn"].ConnectionString);
SqlCommand cmd = new SqlCommand("UP_SelectTableCount", conn);
cmd.CommandType = CommandType.StoredProcedure;
try
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
}
catch{}
finally
{
conn.Close();
}
dt = ds.Tables[0];
metroGrid2.DataSource = dt; }
如何添加或修复我的代码?请帮帮我
谢谢。
【问题讨论】:
-
使用
dataGridView1.Columns.Add(colname) -
谢谢新手。是的,我已经知道如何使用它了。但我想更具体一点
标签: c# winforms datagridview datagridviewcolumn