How to start to edit listview items programatically
How to start to edit listview items programatically
am 30.01.2008 10:30:12 von BZ
Hi,
How to start to edit listview items programatically, like in explorer
when user right click on a file the select Rename?
I know how to make items editable with a click, but I want to add a
button / right click menu for this too
Thanks
Re: How to start to edit listview items programatically
am 30.01.2008 10:49:14 von Jeff Gaines
On 30/01/2008 in message
<9763e4d1-4261-44dc-bcc1-3c64d65dda24@c4g2000hsg.googlegroups.com> bz wrote:
>I know how to make items editable with a click, but I want to add a
>button / right click menu for this too
I use:
private void DoEditItem()
{
// Only handle if 1 item selected
JLVItemEx lvItem = GetSelectedListViewItem();
if (lvItem == null)
{
FireMessageSender(this, "Please Select One Object To Edit", true);
return;
}
m_EditingLabel = true;
lvItem.BeginEdit();
}
private JLVItemEx GetSelectedListViewItem()
{
if (this.SelectedItems.Count != 1)
return null;
return (JLVItemEx)this.SelectedItems[0];
}
The key things being to ensure you have a selected ListViewItem and call
lvItem.BeginEdit();
You need to switch JLVItemEx for ListViewItem if you are using standard
ListViewItems.
Yo need to trap AfterLabelEdit if you want to validate the new text/name.
--
Jeff Gaines
Re: How to start to edit listview items programatically
am 30.01.2008 13:58:32 von BZ
Thanks for answer.
It worked for me just by using BeginEdit (that was the method I was
looking for)
I don't understand what is the other code you wrote. What is it good
for? And what is JLVItemEx
Thanks
On 30 Ian, 11:49, "Jeff Gaines" wrote:
> On 30/01/2008 in message
>
> <9763e4d1-4261-44dc-bcc1-3c64d65dd...@c4g2000hsg.googlegroups.com> bz wrot=
e:
> >I know how to make items editable with a click, but I want to add a
> >button / right click menu for this too
>
> I use:
>
> private void DoEditItem()
> {
> =A0 =A0 =A0 =A0 // =A0 =A0 =A0Only handle if 1 item selected
> =A0 =A0 =A0 =A0 JLVItemEx lvItem =3D GetSelectedListViewItem();
>
> =A0 =A0 =A0 =A0 if (lvItem == null)
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 FireMessageSender(this, "Please Select One=
Object To Edit", true);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return;
> =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 m_EditingLabel =3D true;
> =A0 =A0 =A0 =A0 lvItem.BeginEdit();
>
> }
>
> private JLVItemEx GetSelectedListViewItem()
> {
> =A0 =A0 =A0 =A0 if (this.SelectedItems.Count !=3D 1)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return null;
>
> =A0 =A0 =A0 =A0 return (JLVItemEx)this.SelectedItems[0];
>
> }
>
> The key things being to ensure you have a selected ListViewItem and call
> lvItem.BeginEdit();
> You need to switch JLVItemEx =A0for ListViewItem if you are using standard=
> ListViewItems.
> Yo need to trap AfterLabelEdit if you want to validate the new text/name.
>
> --
> Jeff Gaines
Re: How to start to edit listview items programatically
am 30.01.2008 14:31:15 von Jeff Gaines
On 30/01/2008 in message
bz
wrote:
>Thanks for answer.
>It worked for me just by using BeginEdit (that was the method I was
>looking for)
>
>I don't understand what is the other code you wrote. What is it good
>for? And what is JLVItemEx
JLVItemEx is one of my classes based on a ListViewItem, it has additional
properties like Path, FileType etc.
The code is split into small functions in my library and I just copied and
pasted it.
For instance GetSelectedListViewItem() is a function I use all the time so
having it in a function means I just have to call the function and know I
will either get a valid ListViewItem or null returned, it saves a lot of
repetitive code.
The same with DoEditItem() - it can be called from a menu, the F2 key or
even from outside the file it is in.
--
Jeff Gaines
Re: How to start to edit listview items programatically
am 30.01.2008 15:01:02 von BZ
On 30 Ian, 15:31, "Jeff Gaines" wrote:
> On 30/01/2008 in message
> bz
> wrote:
>
> >Thanks for answer.
> >It worked for me just by using BeginEdit (that was the method I was
> >looking for)
>
> >I don't understand what is the other code you wrote. What is it good
> >for? And what is JLVItemEx
>
> JLVItemEx is one of my classes based on a ListViewItem, it has additional
> properties like Path, FileType etc.
Thanks, I thought it was some NET class I wasn't aware of.
Regards
Bogdan
> The code is split into small functions in my library and I just copied and
> pasted it.
> For instance GetSelectedListViewItem() is a function I use all the time so
> having it in a function means I just have to call the function and know I
> will either get a valid ListViewItem or null returned, it saves a lot of
> repetitive code.
> The same with DoEditItem() - it can be called from a menu, the F2 key or
> even from outside the file it is in.
>
> --
> Jeff Gaines