问题描述
麻烦~帮忙
解决方案
解决方案二:
用模板列,然后可以设置。
解决方案三:
<asp:GridViewID="GridView1"runat="server"><Columns><asp:TemplateFieldControlStyle-Width="100px"HeaderText="设置"><ItemTemplate><!--绑定数据--></ItemTemplate></asp:TemplateField></Columns></asp:GridView>
解决方案四:
<asp:GridViewID="GridView1"runat="server"><Columns><asp:TemplateFieldControlStyle-Width="100px"HeaderText="设置宽度"><ItemTemplate><!--绑定数据--></ItemTemplate></asp:TemplateField></Columns></asp:GridView>
解决方案五:
privatevoidfrmLog_Load(objectsender,System.EventArgse){//设置DataGrid的列宽InitDataGridColumnHeader();//GetResult();}privatevoidInitDataGridColumnHeader(){DataGridTableStyledts=newDataGridTableStyle();//注意:必须加上这一句,否则自定义列格式无法使用dts.MappingName="Table";hrgLog.TableStyles.Add(dts);hrgLog.TableStyles[0].GridColumnStyles.Clear();//========================设置表头栏位===========================DataGridTableStyledtsLog=newDataGridTableStyle();DataGridTextBoxColumncolID=newDataGridTextBoxColumn();colID.Width=80;colID.HeaderText="记录序号";colID.MappingName="ID";hrgLog.TableStyles[0].GridColumnStyles.Add(colID);DataGridTextBoxColumncolLog=newDataGridTextBoxColumn();colLog.Width=200;colLog.HeaderText="日志内容";colLog.MappingName="LogMessage";hrgLog.TableStyles[0].GridColumnStyles.Add(colLog);DataGridTextBoxColumncolTime=newDataGridTextBoxColumn();colTime.Width=100;colTime.HeaderText="记录时间";colTime.MappingName="LogTime";hrgLog.TableStyles[0].GridColumnStyles.Add(colTime);DataGridTextBoxColumncolCatalog=newDataGridTextBoxColumn();colCatalog.Width=100;colCatalog.HeaderText="日志类别";colCatalog.MappingName="LogCatalog";hrgLog.TableStyles[0].GridColumnStyles.Add(colCatalog);
解决方案六:
usingSystem;usingSystem.Drawing;usingSystem.Collections;usingSystem.ComponentModel;usingSystem.Windows.Forms;usingSystem.Data;namespaceWindowsApplication1{///<summary>///SummarydescriptionforForm1.///</summary>publicclassForm1:System.Windows.Forms.Form{privateSystem.Windows.Forms.DataGriddataGrid1;privateSystem.Windows.Forms.DataGridTableStyledataGridTableStyle1;///<summary>///Requireddesignervariable.///</summary>privateSystem.ComponentModel.Containercomponents=null;publicForm1(){////RequiredforWindowsFormDesignersupport//InitializeComponent();////TODO:AddanyconstructorcodeafterInitializeComponentcall//DataTabledt=newDataTable();DataColumndc=newDataColumn("ID",System.Type.GetType("System.Int32"));dt.Columns.Add(dc);DataRowdr=dt.NewRow();dr[0]=1;dt.Rows.Add(dr);dataGrid1.DataSource=dt;dataGrid1.TableStyles[0].GridColumnStyles[0].Width=300;}///<summary>///Cleanupanyresourcesbeingused.///</summary>protectedoverridevoidDispose(booldisposing){if(disposing){if(components!=null){components.Dispose();}}base.Dispose(disposing);}#regionWindowsFormDesignergeneratedcode///<summary>///RequiredmethodforDesignersupport-donotmodify///thecontentsofthismethodwiththecodeeditor.///</summary>privatevoidInitializeComponent(){this.dataGrid1=newSystem.Windows.Forms.DataGrid();this.dataGridTableStyle1=newSystem.Windows.Forms.DataGridTableStyle();((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();this.SuspendLayout();////dataGrid1//this.dataGrid1.DataMember="";this.dataGrid1.HeaderForeColor=System.Drawing.SystemColors.ControlText;this.dataGrid1.Location=newSystem.Drawing.Point(312,208);this.dataGrid1.Name="dataGrid1";this.dataGrid1.Size=newSystem.Drawing.Size(376,232);this.dataGrid1.TabIndex=0;this.dataGrid1.TableStyles.AddRange(newSystem.Windows.Forms.DataGridTableStyle[]{this.dataGridTableStyle1});////dataGridTableStyle1//this.dataGridTableStyle1.DataGrid=this.dataGrid1;this.dataGridTableStyle1.HeaderForeColor=System.Drawing.SystemColors.ControlText;this.dataGridTableStyle1.MappingName="";////Form1//this.AutoScaleBaseSize=newSystem.Drawing.Size(6,14);this.ClientSize=newSystem.Drawing.Size(872,662);this.Controls.Add(this.dataGrid1);this.Name="Form1";this.Text="Form1";((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();this.ResumeLayout(false);}#endregion///<summary>///Themainentrypointfortheapplication.///</summary>[STAThread]staticvoidMain(){Application.Run(newForm1());}}}
-------------------------------------------------必须首先设置一个TableStyles
解决方案七:
你这个家伙,RP这么差,我都给你调试完了你都不揭贴.
解决方案八:
楼上的赞一个