Solved

Editing Listview Subitem

Posted on 2003-10-30
10
2,092 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
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WPF user control poped up from a window 1 48
c#, case, if 4 37
How does GeoJson relates to Leaflet and Mapbox? 4 48
Replace statements HTML with HTML IF 8 63
IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

732 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