Add item in separated rows in listview
Asked Answered
E

4

7

When i add a listview to my form and in form load event i write below code , items added in the same row not in separated rows , how can i add them to separated rows

            listView1.MultiSelect = true;
            listView1.CheckBoxes = true;
            listView1.Items.Add("Item 1");
            listView1.Items.Add("Item 22");
            listView1.Items.Add("Item 333");
Eshelman answered 4/5, 2009 at 9:15 Comment(0)
P
25

try this out

listView1.View = View.List;
Pampas answered 4/5, 2009 at 20:34 Comment(2)
You can also do it in the Visual Studio designer by selecting your ListView object and then in the Properties look for the View item and set the value for that to List.Paving
@Paving I'm just adding this for future readers, but setting it to List doesn't seem to work if you're using groups in the list, it still puts them on separate rows as the OP was requesting, but doesn't retain the groupings. I had to set mine to Details and add an empty column header to get separate rows while retaining groups.Detached
S
7

Taking a stab at this, I'd suggest that it's because your ListView is defaulting to small icons or tiles. Try adding this line anywhere there:

listView1.View = View.Details;
Spongioblast answered 4/5, 2009 at 9:20 Comment(1)
I took this approach but then a header appears. to hide the header use the following code://////////////////////////////////////////////////////////////////////////////////////////////////////// listView1.Columns.Add("someString"); listView1.Columns[0].Width = listView1.Width - 4; listView1.HeaderStyle = ColumnHeaderStyle.None; //////////////////////////////////////////////////////////////////////////////////////////////////////////////// I got that code somewhere on the net once and don't remember where. Don't know how to create code snippet in a comment, sorry.Ioved
S
1

Are you sure ?
Normally, with this code, you should have added 3 items, and you should see 3 rows when the View property of the ListView is set to Details

Sha answered 4/5, 2009 at 9:21 Comment(0)
D
0

You can try listView1.View = View.Tile; There is also a vertical sroll bar.

Dysteleology answered 28/5, 2021 at 15:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.