DataGridView Dgv绑定数据源DataTable dt;
Dgv.DataSource = dt;怎么设置DataGridView 显示 
 dt.Rows[0]["FieldName"]
Dgv.Rows[0].Cells["FieldName"] 值的别名?比如说 dt.Rows[0]["FieldName"]的值是人员编号,通过查询数据库获得对应的人员名称,显示为人员名称。但在
Dgv.Rows[0].Cells["FieldName"].Value 时获取的还是人员编号。熟悉Dephi的知道,可以通过TDataSet 的OnGetText事件 设置 字段的Text 来实现。C#中怎么实现,应该在什么事件中设置??

解决方案 »

  1.   

    1,sql 语句 中有别用
    2,DataGridView  设置表头text
      

  2.   

    我一般是设置DataGridView的属性
      

  3.   


    不是要设置 列的别名,而是 单元格数据的别名,比如column["FieldName"] 中本是人员编号,怎么让显示为人员名称。但是在dt.Rows[0]["FieldName"] 时获取的还是人员编号。
      

  4.   

    不是要设置 列头的别名(HeaderText)
      

  5.   

    写sql语句的时候直接设置别名
      

  6.   

    private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
      if (e.ColumnIndex==2 && e.Value is int)
      {
      int i= (int)e.Value;
      e.Value = "";
      }
    }
      

  7.   

    可惜 DataColumn 没有类似 dataGridView1_CellFormatting的事件,这样的话,同一个table数据源,如果绑定多个dataGridView,就要写多个dataGridView1_CellFormatting的事件