Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
195
Re-arranging columns
posted

Hi,

How can  I re-arrange my columns from code ? My grid is unbound and I am binding it on the fly using grid.datasource = mydatasourcetable. Here my data source table has columns in the order different than I want them on the grid. How can I re-arrange them?

 

thanks,

Yogesh

  • 918
    Suggested Answer
    posted

    In the initialize layout method I use the followng code to set up the columns.  This loops through all the columns in the grid and sets the values I want.  Use the visible position to set the column location.  Column numbering starts at 0.  Sometimes it take a bit of effort to get it just right.  I have had to skip a number and go to the next higher at times to make it order correctly.

    Dim aColumn As UltraGridColumn

     

     

    For Each aColumn In e.Layout.Bands(0).Columns

     

     

    Select Case aColumn.Key

     

     

    Case "Select"

    aColumn.Header.Caption =

    "Select"

    aColumn.Header.VisiblePosition = 0

    aColumn.Width = 59

    aColumn.DataType =

    GetType(Boolean)

    aColumn.AllowGroupBy = DefaultableBoolean.False

    aColumn.Header.Fixed =

    True

     

     

    Case "txtCompanyName"

    aColumn.Header.VisiblePosition = 1

    aColumn.Header.Caption =

    "Company Name"

    aColumn.CellAppearance.TextHAlign = HAlign.Left

     

     

    aColumn.Header.Appearance.TextHAlign = HAlign.Center

    aColumn.ExcludeFromColumnChooser = ExcludeFromColumnChooser.False

     

     

    'aColumn.DataType = GetType(String)

     

     

    Case"datInputDate"

    aColumn.Header.Caption =

    "Input date"

    aColumn.Header.VisiblePosition = 3

    aColumn.Width = 70

     

     

     

     

    Case"txtHomePhone"

    aColumn.Header.Caption =

    "Home Phone"

    aColumn.Header.Appearance.TextHAlign = HAlign.Center

    aColumn.AllowGroupBy = DefaultableBoolean.False

    aColumn.MaskInput =

    "(###) ###-####"

    aColumn.MaskDataMode = Infragistics.Win.UltraWinMaskedEdit.MaskMode.Raw

    aColumn.MaskClipMode = Infragistics.Win.UltraWinMaskedEdit.MaskMode.IncludeBoth

    aColumn.MaskDisplayMode = Infragistics.Win.UltraWinMaskedEdit.MaskMode.IncludeBoth

    aColumn.Header.VisiblePosition = 12

     

     

     

     

    Case Else

    aColumn.Hidden =

    True

    aColumn.ExcludeFromColumnChooser = ExcludeFromColumnChooser.True

     

     

    End Select

     

     

    Next