This project is read-only.

Sizing Columns in ArrayGrid to required length

Apr 20, 2009 at 5:07 PM
Is there a way I can resize the columns in my ArrayGrid to fix the length of the text within the cells, without having all the columns the same size ? If I resize the columns during run-time on the gui, or set the size foreach column, they are always the same length. The largest cell in the grid decides the column width, I would like the largest cell in the column to decide the column width.
Thanks.
Apr 21, 2009 at 5:58 PM
 >                     The largest cell in the grid decides the column width,
 > I would like the largest cell in the column to decide the column

I am not sure what you want to achieve. Do you want any biggest cell in the grid to make all columns to be the same width as that cell? 
Apr 28, 2009 at 9:36 AM
No, that is what is currently happening. The biggest cell in the grid makes all columns the same width as that cell. I would like each column to have a different width.

I've tried to run the extract of code below. During debugging I can see parameter "reqWidth" has a different / correct value, but when viewing the grid all columns has the same size. I don't understand why it's not working.


            for (int col = 0; col <= TestCasesGridArr.Columns.Count; col++)
            {
                int reqWidth = TestCasesGridArr.Columns.MeasureColumnWidth(col, false, 0, TestCasesGridArr.Rows.Count);

                TestCasesGridArr.Columns.SetWidth(col, reqWidth);
            }
May 12, 2009 at 9:03 AM

I really need to solve this urgently as the code needs to go out. Any help would really be appreciated.

May 13, 2009 at 2:48 PM

Why don't you use just Grid ?

Array grid is not sophisticated that much.

Even datagrid has different row and column height feature

May 13, 2009 at 3:13 PM

2 Reasons.

#1 : The documentation states the following : “You can use the Grid control for any kinds of grid where you don't need to display large amounts of cells (typically less than 50.000 cells). If you have to display large amount of cells you must usually use a GridVirtual derived controls, see the next chapters for more information.

#2 : The application is currently working with SourceGrid2. I am merely trying to upgrade to SourceGrid4, because we need more than what is currently offered by SourceGrid2. We are currently using the ArrayGrid functionality and I am just trying to change it to work with the new version of Sourcegrid.

The actual problem is that using ArrayGrid in SourceGrid2 allows us to have columns with different widths, whereas SourceGrid 4 does not allow it. That means that my user are losing functionality instead of gaining.

So the question is : why has this very awesome feature that is totally required been removed ArrayGrid ? Or is there something wrong with my code logic ?

From: dariusdamalakas [mailto:notifications@codeplex.com]
Sent: 13 May 2009 03:49 PM
To: Marli Louwrens
Subject: Re: Sizing Columns in ArrayGrid to required length [sourcegrid:53862]

From: dariusdamalakas

Why don't you use just Grid ?

Array grid is not sophisticated that much.

Even datagrid has different row and column height feature

Read the full discussion online.

To add a post to this discussion, reply to this email (sourcegrid@discussions.codeplex.com)

To start a new discussion for this project, email sourcegrid@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

May 14, 2009 at 10:43 AM

Ok, i see now. Keeping the same functionality is very important.

I don't know why Array grid does not support different widths, i'll try to contact SourceGrid creator and ask why we are having this situation. Maybe it is by design.

Meantime there are two possibilities:

First - Use DataGrid  if thats possible for you. Of course, if the code changes alot, then this option is not for you

Second - use from the trunk. I just commited code, which allows array grid to have different widths for cells. However, rows still have the same width. And i have strong feeling that ArrayGrid should not support this functionality, and DataGrid should be used instead of it

Jan 13, 2010 at 8:40 AM

It looks like I was able to resolve it using the overrides below:


         public override int GetWidth(int column)
        {
            if (column < Grid.FixedColumns) return 40;//fixed
            return Grid.DataSource.GetColWidth(column -  Grid.FixedColumns);

        }
        public override void SetWidth(int column, int width)
        {
            Grid.DataSource.SetColWidth(column - Grid.FixedColumns, width );
            Grid.Refresh();
        }

- JW