Solved

Modify the row of a listview.

Posted on 2011-09-05
3
317 Views
Last Modified: 2013-12-17
Dear Experts,

I have tried to explain my problem in writing, but then the text get
to long and complicated. So I thougt to show it in a picture:

1. When a user click on the toolbar-button.
2. A grey form appears with a not-visible textbox on it.
3. When the user enters text (in this case: "Peter Pan") in the textbox
4. And clicks on the close-button for closing the form.
5. The text "Peter Pan" is now displayed in a listview-column.

This al works great.

But when I double-click on the icon "Peter Pan" again. The form
appears again with the text "Peter Pan" displayed in the textox.
If I know add more text to "Peter Pan", like "Peter Pan is lazy" and
click on the close-button again. The modified text isn't written back
to the listview! How can I do that?

Who knows the answer and is willing to help me? I have added the
toolbar-button-event and the listview double-click-event in the
code-section.

Greetings,

Peter Kiers

private void tbNewNote_Click(object sender, EventArgs e)
        {
            frmNote.textBox1.Clear();
            frmNote.lblCreation.Text = (DateTime.Now.ToString());
            if (frmNote.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                ListViewItem myItem = new ListViewItem(frmNote.textBox1.Text, 0);
                myItem = lvNotes.Items.Add(myItem);
                myItem.SubItems.Add("SubItem1a");
                myItem.SubItems.Add(frmNote.lblCreation.Text);
                lvNotes.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.HeaderSize);
            }
        }

        private void lvNotes_DoubleClick(object sender, EventArgs e)
        {
            frmNote.textBox1.Text = lvNotes.SelectedItems[0].Text;
            frmNote.textBox1.SelectionStart = 0; 
            frmNote.lblCreation.Text = lvNotes.SelectedItems[0].SubItems[2].Text;
            frmNote.ShowDialog();
        }

Open in new window

Example1.jpg
0
Comment
Question by:peterkiers
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 500 total points
Comment Utility
Try this:

        private void lvNotes_DoubleClick(object sender, EventArgs e)
        {
            frmNote.textBox1.Text = lvNotes.SelectedItems[0].Text;
            frmNote.textBox1.SelectionStart = 0;
            frmNote.lblCreation.Text = lvNotes.SelectedItems[0].SubItems[2].Text;
            if(frmNote.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                lvNotes.SelectedItems[0].Text = frmNote.textBox1.Text;
            }
        }

Hope that helps.
0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
My application's behaves very strange with your code.

It think this line is correct but at the wrong place:
 
lvNotes.SelectedItems[0].Text = frmNote.textBox1.Text;


Peter
0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
Thanks. It works.

Peter
0

Featured Post

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

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

11 Experts available now in Live!

Get 1:1 Help Now