Editing Listview Subitem

Posted on 2003-10-30
Last Modified: 2007-12-19

I am working on
I can edit a listview item by setting the labeledit property to true.
Can you please tell me how can I edit the listview subitems? User should just click on the subitem and start editing.
Also, without using any other control ,is it possible to add more items to listview at runtime, like we can add rows in excel sheet.

Pls help me out.

Have a nice day
Question by:lj2222

Expert Comment

ID: 9648811
add items to listview at untime is quite simple:

        Dim myListvItem As ListViewItem

        myListvItem = myListView.Items.Add("some text")
        myListvItem.SubItems.Add("subitem text")
        myListvItem.SubItems.Add("subitem text")
        myListvItem.SubItems.Add("subitem text")

myListvItem is necessary to make a reference to new listview item added

for the first stuff, maybe you can make a new control that inherits listview and implement with your own code the subitems editing.

the edge


Author Comment

ID: 9648900
the edge

I am not looking for adding subitems through code. The user should just click on the new row in the listview and start writing the text. This is what I am looking for.

Can you please tell me which methods I need to edit or modify ,if I inherit the listview control.


Expert Comment

ID: 9648946
ok lj, now i understand.
so why don't you use a datagrid control? it seems to be the thing you wanna get!
or simply, why don'you add a button at the top of the listview, set text to "Add" and when the user click that button shows a form with a textbox and a label for each column of the listview?
i think it's more user friendly, and a good workaround.

the edge

Author Comment

ID: 9649151

I tried using the data grid control,but for no use.
Can you tell me how to use it and also will the users be able to add rows to the datagrid?

I work around suggested by you is a good one, but the requirement of the project is that, the users should be able to edit in the same screen.

waiting for your response
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.


Expert Comment

ID: 9649241
in order to use datagrid, you must bind a datasource to it. here is it a working sample. look at this and costumize it for fitting your needs:

        Dim dr As DataRow


        ds.Tables(0).Columns.Add("Type", System.Type.GetType("System.String"))
        ds.Tables(0).Columns.Add("Qty", System.Type.GetType("System.Int32"))

        dr = ds.Tables(0).NewRow
        dr.Item("Type") = "myProduct1"
        dr.Item("Qty") = 50

        dr = ds.Tables(0).NewRow
        dr.Item("Type") = "myProduct12"
        dr.Item("Qty") = 150

        dr = ds.Tables(0).NewRow
        dr.Item("Type") = "myProduct3"
        dr.Item("Qty") = 500

        With DataGrid1
            .DataSource = ds.Tables(0).DefaultView                     '**** this set the datasource
            .RowHeadersVisible = False                                       '**** this hides the row header
            .CaptionText = "My Caption Text"
            .CaptionVisible = True
            .ReadOnly = False                               '**** IMPORTANT it must be false otherwise you'll cannot add new rows
            .AlternatingBackColor = Color.AliceBlue
        End With

that's all.
if you already got a dataset which contains the value you actually display in the listview, forget the first part of the sample and consider only the block With...End With


the edge
LVL 48

Accepted Solution

Mikal613 earned 125 total points
ID: 9649951
It must be set to report!!!

 ' Set the view to show details.
        ListView1.View = View.Details
        ' Allow the user to edit item text.
        ListView1.LabelEdit = True
        ' Allow the user to rearrange columns.
        ListView1.AllowColumnReorder = True
        ' Display check boxes.
        ListView1.CheckBoxes = True
        ' Select the item and subitems when selection is made.
        ListView1.FullRowSelect = True
        ' Display grid lines.
        ListView1.GridLines = True
        ' Sort the items in the list in ascending order.
        ListView1.Sorting = SortOrder.Ascending

Author Comment

ID: 9655376
the edge,

I have no table to retrieve data from. I have an array from which i need to fetch the data into the data grid. Also, can I edit the fields in the datagrid.

Assisted Solution

the-edge earned 125 total points
ID: 9656128
you can also bind ArrayList to datagrid trough the datasource property.
to learn how to do this.

you can also copy your data for the array to a new dataset, bind the dataset to the datgrid, and then, when it needs, copy the changed data from dataset back to the array.

the edge
LVL 96

Expert Comment

by:Bob Learned
ID: 10232237
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: Mikal613 {http:#9649951} & the-edge {http:#9656128}

Please leave any comments here within the next seven days.

EE Cleanup Volunteer

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now