给DataGrid设置中文列名

很多东西,由不知道,到看到,到调试好,经历了太多的搜索,测试,修改,我怕我遗忘,暂记于此。
  方法一:
 //调用 
 
private void  InsertNull()
  
{
   
try
   
{
       ………………
    DataTable Dtab 
= myDs.Tables[0];
    
    dataGrid1.DataSource 
=Dtab;

    
// 把数字值替换成字符串显示
    ChangeSomeView(Dtab);

    
//设定列名 中文显示
    SetHeaderName(Dtab.TableName);   //处理难点  tablename必须对应才能显示出中文列名
 
  }

   
catch (Exception err)
   
{
    MessageBox.Show(
this,err.Message,"",MessageBoxButtons.OK,MessageBoxIcon.Error);
   }

  
  }

   
/**中文列名****/
 
  
/***设置表头***/
 
方法二:select ID as 顺序号 ,cstr(Type) as  类型     ……  完成列名显示中文的功能。
 
另外的一个小技巧 :select ID ,cstr(Type) as Type   将Type 由INT  提取的时候cstr,然后才能完成替换后的回写 
/// <summary>
  
/// 把数字值替换成字符串显示  1---学生表     
  
/// </summary> 
  
/// <param name="Dtab">DataTable Dtab</param>

  private void ChangeSomeView(DataTable Dtab)
  
{
   
foreach(DataRow Row in Dtab.Rows)
   
{
    
object IDType=Row[1];
    
string operStr=IDType.ToString();
    
switch(operStr)       
    
{         
     
case   "1"  : 
      Row[
1]  = "学生表"  ;
      
break;
  ……    }

   }

  }
 
原文地址:https://www.cnblogs.com/flashicp/p/697065.html