<Columns>
<asp:BoundColumn DataField="title" HeaderText="列标题">
</Columns>

解决方案 »

  1.   

    我的是Winform,还有我想加的不是列头,而是加汉字到每行的最左边的那一个固定列
      

  2.   

    下面给出的例子是加行号,把行号换成你的内容即可。给dataGrid1的事件Paint写方法如下:
    private void dataGrid1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
       int intRow =0; 
       int intCellHehight = dataGrid1.GetCellBounds(intRow, 0).Height + 1; 
       int intY = dataGrid1.GetCellBounds(intRow, 0).Top + 2; 

      e.Graphics.DrawString("行号", dataGrid1.Font, new SolidBrush(Color.Black), 5, intY-intCellHehight-1); //把"行号" 换成你的内容
        CurrencyManager cm = (CurrencyManager) this.BindingContext[dataGrid1.DataSource, dataGrid1.DataMember]; 
     
        while(intY < dataGrid1.Height - intCellHehight && intRow < cm.Count) 
      { 
       //get & draw the header text... 
       string text = string.Format("{0}", (intRow+1)); //把(intRow+1)换成你的内容
       e.Graphics.DrawString(text, dataGrid1.Font, new SolidBrush(Color.Black), 12, intY); 
       intY += intCellHehight; 
       intRow++; 
      } 

    }
      

  3.   

    请问datagrid每行最左边那一列宽度怎么改?RowHeaderWidth属性设置了,怎么不行?
    另外请问gshope(gshope) 固定列怎么加?
      

  4.   

    RowHeaderWidth属性知了还有由于datagrid上有很多列,用滚动条滚动时要保证几列始终显示,固定几列,请问怎么做?
      

  5.   

    用skykevin(蓝屿)提供的方法好象有以下缺点:
    当行很多时,要用滚动条来滚动以便查看下面的记录,可发现下面的记录的行头没显示
    是这样的吗?怎么解决
      

  6.   

    作如下改进:(注意:有“*****”的地方)
    private void dataGrid1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
       int intRow =0; 
       int intCellHehight = dataGrid1.GetCellBounds(intRow, 0).Height + 1; 
       int intY = dataGrid1.GetCellBounds(intRow, 0).Top + 2; 
    int intY0=intY-intCellHehight-1;//**********加新语句
      //e.Graphics.DrawString("行号", dataGrid1.Font, new SolidBrush(Color.Black), 5, intY-intCellHehight-1); //把"行号" 换成你的内容*********移到下面的环后面
        CurrencyManager cm = (CurrencyManager) this.BindingContext[dataGrid1.DataSource, dataGrid1.DataMember]; 
     
        while(intY < dataGrid1.Height - intCellHehight && intRow < cm.Count) 
      { 
       //get & draw the header text... 
       string text = string.Format("{0}", (intRow+1)); //把(intRow+1)换成你的内容
       e.Graphics.DrawString(text, dataGrid1.Font, new SolidBrush(Color.Black), 12, intY); 
       intY += intCellHehight; 
       intRow++; 
      } 
       e.Graphics.DrawString("序号", dg.Font, new SolidBrush(Color.Black), 5, intY0);  //***********移到此
    }