Solved

Automaticly select the row that has been created in a listview.

Posted on 2011-09-28
5
184 Views
Last Modified: 2013-12-17
Hi,

I have a methode to create a row in a listview and it works perfect.
But now I would like when a row is created in the listview it must
be selected too.

Who knows the answer and is willing to help me?

Greetings,

Peter
private void tbNewNote_Click(object sender, EventArgs e)
        {
            frmNote.lblTitle.Text = "";
            frmNote.rtbContent.Clear();
            frmNote.lblCreation.Text = (DateTime.Now.ToString());
            if (frmNote.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                ListViewItem myItem = new ListViewItem(frmNote.lblTitle.Text, 0);
                myItem = lvNotes.Items.Add(myItem);
                myItem.SubItems.Add(frmNote.rtbContent.Text);
                myItem.SubItems.Add(frmNote.lblCreation.Text);
                //select the created row 
            }
        }

Open in new window

0
Comment
Question by:peterkiers
[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
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:jatkin
ID: 36715999
Hi,
Does the .Add method not return the new entry?
You should be able to use this to locate and select in the list...
James
0
 
LVL 1

Author Comment

by:peterkiers
ID: 36716010
No, it doesn't automaticly select the row.

P.
0
 
LVL 4

Accepted Solution

by:
jatkin earned 500 total points
ID: 36716014
It's a while since I did this, but can you not set the 'Selected' property to true?
0
 
LVL 1

Author Comment

by:peterkiers
ID: 36716028
It works. Thanks. Peter
0
 
LVL 4

Expert Comment

by:jatkin
ID: 36716030
No problem.... :-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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