Moleman
Moleman

Reputation: 87

Set Listviewitem's width

I have a Listview and it has one column. The view is set to List and I can see each Listviewitem but I can't select the item's row, I have to select the item's text. Is it possible to make it so that the Listviewitem's width is the same size as the Listview itself so that the user can click anywhere on the Listviewitem to select the item?

I tried searching but could only find how to change the column width and how to fix it in XAML, but this is for a WinForm.

Edit - As requested, this is the code that is generated by the Visual Studio designer. It is the only code involved with the ListviewItem.

System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("1");
System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("2");
System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem("3");
System.Windows.Forms.ListViewItem listViewItem4 = new System.Windows.Forms.ListViewItem("4");
System.Windows.Forms.ListViewItem listViewItem5 = new System.Windows.Forms.ListViewItem("5");
System.Windows.Forms.ListViewItem listViewItem6 = new System.Windows.Forms.ListViewItem("6");
System.Windows.Forms.ListViewItem listViewItem7 = new System.Windows.Forms.ListViewItem("7");
this.listView1 = new System.Windows.Forms.ListView();

this.listView1.Activation = System.Windows.Forms.ItemActivation.OneClick;
            this.listView1.AllowDrop = true;
            this.listView1.AutoArrange = false;          
            this.listView1.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.listView1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.listView1.ForeColor = System.Drawing.SystemColors.MenuHighlight;
            this.listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
            listViewItem1.StateImageIndex = 0;
            this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
            listViewItem1,
            listViewItem2,
            listViewItem3,
            listViewItem4,
            listViewItem5,
            listViewItem6,
            listViewItem7});
            this.listView1.Location = new System.Drawing.Point(105, 129);
            this.listView1.Name = "listView1";
            this.listView1.Size = new System.Drawing.Size(157, 475);
            this.listView1.TabIndex = 4;
            this.listView1.UseCompatibleStateImageBehavior = false;
            this.listView1.View = System.Windows.Forms.View.List;

Upvotes: 1

Views: 7624

Answers (3)

Falo
Falo

Reputation: 371

Set listView1.FullRowSelect = true

Upvotes: 0

Libor
Libor

Reputation: 3303

Better ListView and Better ListView Express (free) support this. It behaves like a ListBox by default (Details view, no columns):

enter image description here

The item auto sizing can be triggered by setting AutoSizeItemsInDetailsView property to true:

betterListView.AutoSizeItemsInDetailsView = true;

Upvotes: 0

Wolf
Wolf

Reputation: 2150

A simple solution will be using a ListBox instead of List View

In case of simple text, it is better to use ListBox.

Update:

Simplest hack for getting this functionality in ListView will be adding dummy spaces at the end of each item string to fill.

Upvotes: 4

Related Questions