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
635
How to easilty customise grid columns by their data type
posted

Hi

I use Ultragrids, attach a data source and then customise the columns in the grid's designer. But if there are hundreds of columns, it's very slow and cumbersome to change each column one by one.

While I can hide and exclude from the field chooser a subset of columns, there are some settings we like to apply to all columns of a specific datatype. For example we like numeric columns to be right aligned, not left. We like the FilterOperandDropDownItems to be Custom for numeric columns and Customs & Blanks for String columns. Now I've managed to do this at run-time but it can take over a second to do this when the grid has 300 columns.

I had a look at presets but they don't seem to allow customisation by column Datatype.

Is there a more efficient way to do this either at design-time or run-time?

Thanks

John

Parents
  • 7695
    Verified Answer
    Offline posted

    Hi John,

        I really wouldn't recommend using the designer when dealing with more than 10 columns or so. It can be done, and the end result may be slightly more efficient, but even dealing with 300 or 5000 columns looping through them shouldn't be any more noticeable time to process. I am not sure how you are currently doing it, but the way I would handle a scenario like that would be to use the InitializeLayout event. This event fires when you set the DataSource property of the grid. In it you have the e.Layout event arg, in which equates to the DisplayLayout of the grid. So for a single band grid with 300 columns I would just loop through the columns there, via e.Layout.Bands[0].Columns, and then just handle what you need to there.
    foreach(UltraGridColumn column in e.Layout.Bands[0].Columns)
    {
        if (column.DataType == typeof(string))
         ...

    }

    The only way I could imagine you might get a bit more speed out of a looping scenario, or more specifically you might slow down a looping scenario is if you created your appearance objects inside the loop. If you have a set number of appearance changes that you want applied. Instead of setting them all inside the loop which then would instantiate an appearance object for each. Define them outside of the loop and set the appropriate appearance property to the instance.

    Hope this helps,

Reply Children