Back to Devexpress

WebColumnBase.Width Property

aspnet-devexpress-dot-web-dot-webcolumnbase-94cb8986.md

latest3.5 KB
Original Source

WebColumnBase.Width Property

Gets or sets the column’s width.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
[DefaultValue(typeof(Unit), "")]
public virtual Unit Width { get; set; }
vb
<DefaultValue(GetType(Unit), "")>
Public Overridable Property Width As Unit

Property Value

TypeDefaultDescription
UnitString.Empty

A Unit structure that represents the column’s width.

|

Remarks

The Width property specifies the width for the WebColumnBase class’s derived objects. The WebColumnBase class serves as a base class for the following objects:

  • Web Forms and MVC Grid-like components’ columns.
  • Gantt columns.
  • ListBox columns.
  • and others.

Note

It is recommended that you specify the Width property in pixels or percentage to ensure grid columns’ correct render. In certain scenarios (for example, the use of the Min or Max column widths) the grid’s internal calculation algorithm may calculate the column width incorrectly if you specify column widths in other units (em, pt and others).

Example

ASPxGridView :

aspx
<dx:ASPxGridView ID="Grid" runat="server" >
    <Columns>
        <dx:GridViewDataColumn FieldName="ContactName" Width="150" FixedStyle="Left" />
        <dx:GridViewDataColumn FieldName="CompanyName" Width="180" FixedStyle="Left" />
        <dx:GridViewDataColumn FieldName="City" Width="130" />
        ...
    </Columns>
</dx:ASPxGridView>

ASPxListBox :

aspx
<dx:ASPxListBox ID="lbModels" runat="server" ...>
    <Columns>
        <dx:ListBoxColumn FieldName="Name" Caption="Model" Width="100%" />
        <dx:ListBoxColumn FieldName="Price" Width="50px" />
    </Columns>
</dx:ASPxListBox>

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Width property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

gridview-how-to-correct-the-grouped-table-layout-if-column-widths-are-set-in-percentages-t349964/CS/Helpers/GridViewColumnHelper.cs#L30

csharp
{
    Grid.Columns[keyPairValue.Key].Width = Unit.Percentage(keyPairValue.Value);
}

See Also

WebColumnBase Class

WebColumnBase Members

DevExpress.Web Namespace