C1GridView Column Width issues

Posted by: nutekguy on 17 January 2018, 9:11 pm EST

    • Post Options:
    • Link

    Posted 17 January 2018, 9:11 pm EST

    How do you get & set the column width? Per your example, I set the AuoGenerateColumn to “False”.

    for (int i = 0; i < C1GridViewMain.Columns.Count-1; i++)
            {
                C1GridViewMain.Columns[i].ItemStyle.Width = C1GridViewMain.Columns[i].ItemStyle.Width *2; //Does not compile
                C1GridViewMain.Columns[i].Width = C1GridViewMain.Columns[i].Width*2; //Does not compile
                C1GridViewMain.Columns[i].Width=200; //Compiles and works fine.
            }
    

    Any ideas?

  • Posted 18 January 2018, 10:10 pm EST

    Hi,

    Since the column width value is of object type and contains some property e.g. Value, Type.

    Also, the width property is type of unit with Pixel type. You may access the width using width.Value.

     var width = C1GridView1.Columns[0].Width;
                var nWidth = width.Value * 2;
                C1GridView1.Columns[0].Width = Unit.Percentage(nWidth);
    

    You may also change the width of column using client side properties as following code snippet:

     function resizeColumns() {
                var grid = $("#C1GridView1").c1gridview("option");
                for (var i = 0; i<grid.columns.length; i++) {
                    var width = parseInt(grid.columns[i].width);
                    if (Number(width)) {
                        grid.columns[i].width = (width * 2) + 'px';
                    }
                }
            }
    
    

    Hope it helps!

    ~Manish

  • Posted 18 February 2018, 3:27 pm EST

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels