Peter Kiers
asked on
Select a new row in a listview.
Hi,
I have a listview with 1 button on my form, and the listview is connected to a database.
When I press on the button a childform appears with a textbox on it where the user
can enter text. After pressing the x-button of the childform the text of the textbox will be
written on the listview on the mainform, so a new row will be inserted into the listview.
But how can I automaticly select the new inserted row in the listview?
private void barButtonItem1_ItemClick(o bject sender, DevExpress.XtraBars.ItemCl ickEventAr gs e)
{
if (frmNote.ShowDialog() == System.Windows.Forms.Dialo gResult.Ca ncel)
{
listView1.Items.Add(frmNot e.textBox1 .Text, 0);
//SELECT THE NEW INSERTED ROW
}
}
Greetings, Peter Kiers
I have a listview with 1 button on my form, and the listview is connected to a database.
When I press on the button a childform appears with a textbox on it where the user
can enter text. After pressing the x-button of the childform the text of the textbox will be
written on the listview on the mainform, so a new row will be inserted into the listview.
But how can I automaticly select the new inserted row in the listview?
private void barButtonItem1_ItemClick(o
{
if (frmNote.ShowDialog() == System.Windows.Forms.Dialo
{
listView1.Items.Add(frmNot
//SELECT THE NEW INSERTED ROW
}
}
Greetings, Peter Kiers
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
private void barButtonItem1_ItemClick(o bject sender, DevExpress.XtraBars.ItemCl ickEventAr gs e)
{
if (frmNote.ShowDialog() == System.Windows.Forms.Dialo gResult.Ca ncel)
{
listView1.Items.Add(frmNot e.textBox1 .Text, 0);
//select the new item <========================= ==
}
}
{
if (frmNote.ShowDialog() == System.Windows.Forms.Dialo
{
listView1.Items.Add(frmNot
//select the new item <=========================
}
}
You can this piece of code:
ListViewItem lv = new ListViewItem(frmNote.textBox1.Text, 0);
ListView1.Items.Add(lv);
ListView1.Focus();
ListView1.SelectedItems.Clear();
ListView1.Items(ListView1.Items.Count - 1).Selected = true;
ASKER
I have tested the code but it does not select the node.
Peter