【问题标题】:DataGridView and SQL query nameDataGridView 和 SQL 查询名称
【发布时间】:2016-05-03 20:39:47
【问题描述】:

我有一个函数可以从数据库中获取所有数据(还有列名)并将其显示在 DataGridView 中。

问题在于 DataGrid 还显示列名。如何编辑列名称?我已经试过了

dataGridView1.Columns[0].Name = "xxx"; 

没有成功。

private void PriceChange_Load(object sender, EventArgs e)
{
      DbCards d = new DbCards();

      dataGridView1.DataSource = d.GetAllcards().Tables[0];
}

GetAllcards()select * from Cards

【问题讨论】:

    标签: c# sql datagridview


    【解决方案1】:

    如果要更改 DataGridViewColumn 显示的标题文本,您需要使用 HeaderText 属性

    dataGridView1.Columns[0].HeaderText = "xxx";
    

    【讨论】:

      【解决方案2】:

      改为设置dataGridView1.Columns[0].HeaderText

      【讨论】:

        猜你喜欢
        • 2017-03-09
        • 2012-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-15
        相关资源
        最近更新 更多