要达到2个目的
1,如果ColumnHeader是最宽的 该列的宽度设置为它
2,如果ColumnContent是最宽的,也就是显示的内容 则设置为它。
现在写的代码如下:
  this.dgView.DataSource = dt.DefaultView;
this.dgView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;                
                this.dgView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);现在这样的写法只能让宽度随着Content的变化而变化,因此 Header有时候会折叠,请教写法。

解决方案 »

  1.   

    将tableLayout设置成fixed就可以了
      

  2.   

    DataGridView的 tableLayout?没有这个属性阿
      

  3.   

    this.DataGridView.Attributes.Add("style", "tableLayout:fixed;");
      

  4.   

    我的是 WinForm 不是Web的
      

  5.   

    DataGridViewAutoSizeColumnsMode.None; 改成DataGridViewAutoSizeColumnsMode.ColumnHeader
     The column widths adjust to fit the contents of the column header cells.  
      

  6.   

    判断字符串的长度,来设定他的宽度。str = XXX;
     if(str.Length >=30)
    {
        column.width=80;
    }
     .....
      

  7.   

    将tableLayout设置成fixed就可以了