Culture prevents listview columns autosizing?

Happy new year all,

I have discovered a problem in the Compact Framework that can only be
reproduced by running the same code against an English and German
emulator/device.

I am setting ColumnHeader.Width to -1 and -2, to find the best fit for each
column. Setting the width to -1/-2 does autosize the column on my English
devices/emulator, but fails completely when run against a German emulator
(the width is only set to 0). Example of the code:

foreach (ColumnHeader ch in listView.Columns)
{
// get width by column header text
ch.Width = -2;
int w = ch.Width;

// now get longest item width
ch.Width = -1;

// is this less than the column header width
if (ch.Width < w)
{
// yes - then use the column header width
ch.Width = w;
}
}

More example code at end of post...

There is seemingly no rhyme or reason for this, and I cannot say I expect to
get much more than confirmation back from you guys that this is an issue, but
that at least would make me feel sane!!

Rob

--

More example test case code:

public Form1()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.listView1 = new System.Windows.Forms.ListView();

this.listView1.Location = new System.Drawing.Point(8, 8);
this.listView1.Size = new System.Drawing.Size(224, 184);
this.listView1.HeaderStyle = ColumnHeaderStyle.Nonclickable;
this.listView1.View = View.Details;

this.Controls.Add(this.listView1);
this.Menu = this.mainMenu1;
this.Text = "Form1";

this.Load += new System.EventHandler(this.Form1_Load);
}

private void Form1_Load(object sender, System.EventArgs e)
{
for (int i = 0; i < 3; i++)
{
ColumnHeader ch = new ColumnHeader();
ch.Text = "Column" + i;
listView1.Columns.Add(ch);
}

foreach (ColumnHeader ch in listView.Columns)
{
// get width by column header text
ch.Width = -2;
int w = ch.Width;

// now get longest item width
ch.Width = -1;

// is this less than the column header width
if (ch.Width < w)
{
// yes - then use the column header width
ch.Width = w;
}
}
}


Answer this question

Culture prevents listview columns autosizing?

  • scenedamaged

    David,

    Thanks for your help here, I apologise for not including this first time round.

    Visual Studio 2003 v7.1.3088
    .NETCF 1.0.5000

    PPC2002 Emulator images came from:
    http://www.microsoft.com/downloads/details.aspx FamilyID=25f4de97-ae80-477a-9df1-496b85b3d3e3&DisplayLang=en

    The issue can also be reproduced on a Windows Mobile 5 device.

    Is it possible for the version of the framework to differ between devices, if Visual Studio is deploying the compact framework libraries as it deploys the application

    Regards,

    Robert

  • pixelstuff

    Can you describe the versions of everything you are using

    E.G.

    Visual Studio 2005

    .NETCF 2.0 Sp1

    German localized emulator image acquired from http://www.microsoft.com/downloads/details.aspx FamilyID=EEC33AE3-C129-4C25-ABAA-18E8E842178F&displaylang=en&Hash=%2bHLVKEo4eEHDjpkAVGKL3%2ffEbXyxli144Qkjkyn6lR2e%2bs5m1DXHI6BSdvbg0EaxmQbVrWvUN2VYeki1i53Krg%3d%3d

    Etc.

    I tried your repro on our .NETCF 2.0 on a Windows Mobile 5.0 german emulator and it did not reproduce. One possible difference between your english device and your german device is that you may have a different version of .NETCF installed.

    David Wrighton

    .NET Compact Framework


  • Culture prevents listview columns autosizing?