你在一个DataTable中怎么可能指定列宽,一个表中只有数据的,没有什么列宽的概念。只能说是在显示表中数据的控件中显示列的宽度吧。比如dataGrid

解决方案 »

  1.   


    ds.Tables[0].Columns[0].MaxLength = 100;
      

  2.   

    那在dataGrid中如何搞呢??DataColumn col = new DataColumn;
    col = new DataColumn();
    col.ColumnName = "序号";
    col.DataType = System.Type.GetType("System.String");
    dt.Columns.Add(col);
    DataGrid.DataSource = dt;
    DataGrid.DataBind();
      

  3.   

    anycat(有猫就好) 请回答DataGrid.DataSource = dt;
    DataGrid.DataBind();用以上代码不行???
    那请你写2句可以的
      

  4.   

    BearRui(我有点笨,但我很特别,所以我特别笨!) 请回答DataGrid.DataSource = dt;
    DataGrid.DataBind();
    如何在DataGrid中写??
      

  5.   

    不是辣~~~我的意思是自动绑定的话,除非用遍历datagrid的cell,要不然还真的不知道怎么设置了~~~因为自动绑定的话,绑定之前,column是不定的嘛~ @_@ ~
      

  6.   

    不是自动绑定的话,可以在属性编辑器里进行设置嘛。在datagrid上右键->属性编辑器(Property Builder...)->格式(Format)->就可以看到设置了咯。
      

  7.   

    或者在绑定之后
    DataGrid.Columns[0].ItemStyle.Width
    晕倒,刚刚试了一下,竟然可以这样滴~咳咳~
      

  8.   

    自己创建一个DataView可以做到的!
    仔细的我也不太清楚!你查查MSDN吧!
      

  9.   

    回复人: anycat(有猫就好) ( ) 信誉:99 
    你说的那条语句往那里加啊??我怎么出错啊
    DataGrid.DataSource = dt;
    DataGrid.DataBind();
    以上是绑定
      

  10.   

    DataGrid.DataBind();
    在帮定之后再
    DataGrid.Column[0].ItemStyle.Width
    具体可以参考MSDN咯。
      

  11.   

    foreach(DataGridColumn col in this.dtgNoteList.Columns)
    {
    if(col.ColumnName == "abc")
    {
    col.ItemStyle = "abc";//CSS class name
    }
    }
    也可以这样玩~ ^o^ ~
    点net嘛,随便点点就知道怎么玩了嘛~ ^_^ ~
    当然,因为绑定之后才有数据啊啥的,所以这些格式化什么的东东最好在DataGrid.DataBind()之后做。