大流氓出没 2017-03-15 02:02 采纳率: 50%
浏览 1920

winform中的GridView如何对每列添加数据源?

问题如题
我想要弄一个表 用GIRDVIEW控件 但是这张表的5列数据来自数据库中的三个表 我直接用GIRDVIEW自带的配置功能去配置只能配置一个数据源 我想问下的就是是不是只能用代码生成表格然后把表格绑到控件上,而不能直接在datagridview上配置多个数据源的?

  • 写回答

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 动力学代码报错,维度不匹配