你这个不是删除列,怎么用起XXXStyle来了??

解决方案 »

  1.   

    maybe you can set its width to zero.To set a column width, your datagrid must be using a non-null DataGridTableStyle. Once this is in place, you can set the column width by first getting the tablestyle and then using that object to obtain a column style with which you can set the width. Here are some code snippets showing how you might do this. 
     
    //.... make sure your DataGrid is using a tablestyle 
     
    dataGrid1.DataSource = _dataSet.Tables["customers"]; 
     
    DataGridTableStyle dgts = new DataGridTableStyle(); 
     
    dgts.MappingName = "customers"; 
     
    dataGrid1.TableStyles.Add(dgts); 
      
    //...... 
      
    //method to set a column with by colnumber 
     
    public void SetColWidth(DataGridTableStyle tableStyle, int colNum, int width) 
     

     
         try 
     
         { 
     
              tableStyle.GridColumnStyles[colNum].Width = width; 
     
              tableStyle.DataGrid.Refresh(); 
     
         } 
     
         catch{} //empty catch .. do nothing 
     

      
    //.... 
      
    // here is how you might call this method 
      
    private void button1_Click(object sender, System.EventArgs e) 
     

     
         DataGridTableStyle tableStyle = dataGrid1.TableStyles["customers"]; 
     
         SetColWidth(tableStyle, 1, 200); 
     
    }
      

  2.   

    MSDN上的例子就是这样。你可以告诉我应该怎么实现么
      

  3.   

    <asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False" Width="645px" DataKeyField="userid">html下的,,,注意DataKeyField
      

  4.   

    To codo: Windows的应用程序中,DataGrid没有设置DataKey这一项的。webform中是有的。
    To Turbo:我不是要隐藏某一列。。我是想删掉一列
      

  5.   

    这个就是MSDN的示例代码:
    http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/vbcon/html/vbtskcreatingcustomcolumntypesindatagrid.asp
      

  6.   

    To  trnbo:你的那段我不能用报的错和原来一样