Solved

Editing Listview Subitem

Posted on 2003-10-30
10
2,087 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
10 Comments
 
LVL 3

Expert Comment

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

Author Comment

by:lj2222
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

9 Experts available now in Live!

Get 1:1 Help Now