Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Setting Column Width in MultiColumn ListBox
Hi Gintaras,
I am trying to figure out how to set column width in MultiColumn List Box.
I found this on MSDN

but don't know how to use that in QM.

Thanks for any help!

Don't remember. Maybe it is impossible. Look in MSDN, maybe there is a message or style.
Hi Gintaras,

maybe I am closer to this then I realize...from the MSDN example I see

Quote:this.listBox1.ColumnWidth = 85

this is from a fuller description and example of ListBox properties from that I have pasted below. I just don't know how to translate that into the style options that arise in the dialog screen....maybe this example will show me how to do it by myself in the future :oops:

truly thanks for any help and I understand if you are too busy at this time to help out.


Quote:.NET Framework Class Library
ListBox..::.ColumnWidth Property

Gets or sets the width of columns in a multicolumn ListBox.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic (Declaration)
Public Property ColumnWidth As IntegerVisual Basic (Usage)
Dim instance As ListBox
Dim value As Integer

value = instance.ColumnWidth

instance.ColumnWidth = valueC#
public int ColumnWidth { get; set; }Visual C++
property int ColumnWidth {
int get ();
void set (int value);
public function get ColumnWidth () : int
public function set ColumnWidth (value : int)
Property Value
Type: System..::.Int32
The width, in pixels, of each column in the control. The default is 0.

Exception Condition
ArgumentException A value less than zero is assigned to the property.

If you set the value to zero (0), a default width is assigned to each column. If the ListBox is a multicolumn ListBox, this property returns the current width of each column in the list. You can use this property to ensure that each column in a multicolumn ListBox can properly display its items.

The following code example demonstrates a simple two-column ListBox.

Visual Basic Copy Code
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms

Public Class Form1
Inherits Form
Private listBox1 As ListBox

Public Sub New()
End Sub

<STAThread()> _
Shared Sub Main()
Application.Run(New Form1())
End Sub

Private Sub InitializeComponent()
Me.listBox1 = New System.Windows.Forms.ListBox()
' listBox1
Me.listBox1.FormattingEnabled = True
Me.listBox1.HorizontalScrollbar = True
Me.listBox1.Items.AddRange(New Object() {"Item 1, column 1", "Item 2, column 1", "Item 3, column 1", "Item 4, column 1", "Item 5, column 1", "Item 1, column 2", "Item 2, column 2", "Item 3, column 2"})
Me.listBox1.Location = New System.Drawing.Point(0, 0)
Me.listBox1.MultiColumn = True
Me.listBox1.Name = "listBox1"
Me.listBox1.ScrollAlwaysVisible = True
Me.listBox1.Size = New System.Drawing.Size(120, 95)
Me.listBox1.TabIndex = 0
Me.listBox1.ColumnWidth = 85
' Form1
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Name = "Form1"
End Sub
End Class
C# Copy Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
private ListBox listBox1;

public Form1()
static void Main()
Application.Run(new Form1());

private void InitializeComponent()
this.listBox1 = new System.Windows.Forms.ListBox();
// listBox1
this.listBox1.FormattingEnabled = true;
this.listBox1.HorizontalScrollbar = true;
this.listBox1.Items.AddRange(new object[] {
"Item 1, column 1",
"Item 2, column 1",
"Item 3, column 1",
"Item 4, column 1",
"Item 5, column 1",
"Item 1, column 2",
"Item 2, column 2",
"Item 3, column 2"});
this.listBox1.Location = new System.Drawing.Point(0, 0);
this.listBox1.MultiColumn = true;
this.listBox1.Name = "listBox1";
this.listBox1.ScrollAlwaysVisible = true;
this.listBox1.Size = new System.Drawing.Size(120, 95);
this.listBox1.TabIndex = 0;
this.listBox1.ColumnWidth = 85;
// Form1
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form1";


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

See Also
ListBox Class
ListBox Members
System.Windows.Forms Namespace
Tags : Add a tag Add Cancel Flag as ContentBug
.NET code usually cannot be translated to QM.
thanks Gintaras. What do you call the Win API code that QM "lives in" .... Win32? Is that a predecessor to .NET or is .NET something different altogether. Still trying to explain to people what "language" I am doing all my QM magic in!!!!!


ps... the help in finding the changing .NET window controls was very helpful though!!!!
DotNetControls.qml [4.01 KiB]
.NET wraps Windows API to make programming easier.

Forum Jump:

Users browsing this thread: 1 Guest(s)