问题如题
我想要弄一个表 用GIRDVIEW控件 但是这张表的5列数据来自数据库中的三个表 我直接用GIRDVIEW自带的配置功能去配置只能配置一个数据源 我想问下的就是是不是只能用代码生成表格然后把表格绑到控件上,而不能直接在datagridview上配置多个数据源的?
winform中的GridView如何对每列添加数据源?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- Nolanamy 2017-03-15 05:03关注
public static void Set_DataGridView(DataGridView dataGridView, string tableName, ToolStripProgressBar toolStripProgressBar)
{
dataGridView.Rows.Clear();
dataGridView.Columns.Clear();
DataTable dt = Methods.Methods_MDB.SelectMdb("select * from " + tableName, ConstClass.mdbPath, ConstClass.provider);
List fileNames = Get_FileName(tableName);
List heater = new List();
toolStripProgressBar.Maximum = dt.Rows.Count;
dataGridView.ColumnCount = fileNames.Count;
for (int i = 0; i < dt.Rows.Count; i++)
{
toolStripProgressBar.Value = i + 1;
for (int f = 0; f < fileNames.Count; f++)
{
if (fileNames[f].Equals("编号") || fileNames[f].Equals("ID"))
{
dataGridView.ColumnHeadersVisible = false;
}
else
{
dataGridView.ColumnHeadersVisible = true;
}
dataGridView.Columns[f].Name = fileNames[f];
}
dataGridView.Rows.Add();
for (int f = 0; f < fileNames.Count; f++)
{
dataGridView.Rows[dataGridView.Rows.Count - 2].Cells[fileNames[f]].Value = dt.Rows[i][fileNames[f]].ToString();
}
}
}解决 无用评论 打赏 举报
悬赏问题
- ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
- ¥15 C# datagridview 单元格显示进度及值
- ¥15 thinkphp6配合social login单点登录问题
- ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配