?
Solved

Editing Listview Subitem

Posted on 2003-10-30
10
Medium Priority
?
2,094 Views
Last Modified: 2007-12-19
Hi

I am working on vb.net
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
lj
0
Comment
Question by:lj2222
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 3

Expert Comment

by:the-edge
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

0
 

Author Comment

by:lj2222
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.

lj
0
 
LVL 3

Expert Comment

by:the-edge
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
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

Author Comment

by:lj2222
ID: 9649151
the-edge

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
lj
0
 
LVL 3

Expert Comment

by:the-edge
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.Add("MyTables")

        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
        ds.Tables(0).Rows.Add(dr)

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

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

        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

bye

the edge
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 500 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
0
 

Author Comment

by:lj2222
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.
0
 
LVL 3

Assisted Solution

by:the-edge
the-edge earned 500 total points
ID: 9656128
you can also bind ArrayList to datagrid trough the datasource property.
see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridtablestyleclassmappingnametopic.asp
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
0
 
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.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

764 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