3
Answers

Add controls to listview subitem

Photo of kehinde adeoya

kehinde adeoya

13y
7.5k
1
 [code]private void MainTimesheetForm_Load(object sender, EventArgs e)
        {
            ListViewItem newList = new ListViewItem("RN", 0);
            newList.SubItems.Add("2");
            newList.SubItems.Add(DateTime.Now.ToLongTimeString());
            newList.SubItems.Add("3");
            newList.SubItems.Add("4");
            newList.SubItems.Add("5");
            newList.SubItems.Add("6");
            listViewTimeSheet.Items.Add(newList);
            ListViewItem newList2 = new ListViewItem("items", 1);
            newList.SubItems.Add("2");
            newList.SubItems.Add(DateTime.Now.ToLongTimeString());
            newList.SubItems.Add("3");
            newList.SubItems.Add("4");
            newList.SubItems.Add("5");
            newList.SubItems.Add("6");
            listViewTimeSheet.Items.Add(newList2);
}[/code]
           Please how do i add control to a subItem in listview. Thanks.
 

Answers (3)

0
Photo of Sam Hobbs
NA 28.7k 1.3m 13y
As the otehr memers have indicated, it helps to be specific about what the UI is; whether it is ASP.Net, WPF, Windows Forms or whatever. The best way to do that is to put the question in the forum for tha UI; this forum is for questions about the C# language, not all questions about everything and anything developed using C#. This is a UI question, not a language question.

Assuming you are asking about a Windows Forms application, the ListView control is quite old. It was initially developed for the Windows Explorer accessory in Windows 95. It is less flexible than the newer controls.
0
Photo of Vulpes
NA 98.3k 1.5m 13y
I suspect kehinde may be talking about the ListView in Windows Forms but, to the best of my knowledge, you can't add controls as (or to) sub-items of that either.
0
Photo of Senthilkumar
NA 15.2k 2.4m 13y
Hi,

Are you talking about ListView in asp.net or ListBox in asp.net?

Because you can't add the items like this in ListView control.

If you want to implement like this then you can go for

TreeView
or
Nested DataControls 

I have written two articles for nested data controls and treeview.

http://www.c-sharpcorner.com/uploadfile/skumaar_mca/nested-data-controls-in-Asp-Net/
http://www.c-sharpcorner.com/UploadFile/skumaar_mca/tree-view-control-with-an-example/