Solved

Editing Listview Subitem

Posted on 2003-10-30
10
2,093 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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 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
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 125 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 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