extender callback

I have an extender fora listview. I want it to raise events and pass info back to the form it's on. Since you can't assign delegates using the IDE, is there a way to get this to happen without requiring any hand code by the user?
:eek:
[257 byte] By [FoodBard] at [2007-11-20 0:04:05]
# 1 Re: extender callback
How did you do the extension? Did you derive from ListView? Did you derive from UserControl and encapsulated the ListView?
If you did one of those options then any event you add to your control should be visible in the Designer.
jhammer at 2007-11-9 11:24:34 >
# 2 Re: extender callback
No, I made an iextender
FoodBard at 2007-11-9 11:25:35 >
# 3 Re: extender callback
Still can't work it out. If I set delegate as an extender prop it is greyed in IDE.
And events don't show in the component.
FoodBard at 2007-11-9 11:26:33 >
# 4 Re: extender callback
you should be able to pass the instance of the form into the extender, then pass event driven data to the form directly from your provider. its been a while since I looked at extender providers, but I'm sure a search of code project would prove useful.
MadHatter at 2007-11-9 11:27:38 >
# 5 Re: extender callback
I think you've lost me. At the moment, everything works. However I have to add the delegate code by hand instead of using the designer.this is not very good because the user of the extender component will see all these properties in the designer but it will not be clear that they need to add another line in code to add the delegate.

I have extended the list into accept drop files. When a group of files are dropped, I want to fire off an event for each individual file.

Since I'm only extending the list view, the documentation says that it is better to d an extender rather than to derive from list view. So I have set up all the properties, except that there is no way to add new events with an extender that I can find.
FoodBard at 2007-11-9 11:28:38 >
# 6 Re: extender callback
the procider property will match whatever type of control you are wanting to extend (again, sorry for the lack of detail because it has been a while).

get_PropertyName(Button b) { ... }
set_PropertyName(Button b, SomethingElse se) { ... }

in the extender code when you get the object you're extending you either use one of the designer services to set the event handler or do wire it directly through code.
MadHatter at 2007-11-9 11:29:37 >
# 7 Re: extender callback
here's an example:

using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;
using System.Drawing;

namespace WindowsApplication1 {
public delegate void ListViewClickedHandler(object sender, ListViewClickedEventArgs e);
public class ListViewClickedEventArgs : EventArgs {
int column = -1;
public int Column{ get { return column; } }
public ListViewClickedEventArgs(int col) { column = col; }
}
[ProvideProperty("ListViewClickFeedback", typeof(ListView))]
public class MyExtender : Component, IExtenderProvider {
Dictionary<ListView, bool> listviews = new Dictionary<ListView, bool>();

ColumnClickEventHandler extendedClicked;
public event ListViewClickedHandler ListViewClick;
protected virtual void OnListViewClick(ListViewClickedEventArgs e) {
if(ListViewClick != null) ListViewClick(this, e);
}
public MyExtender() {
extendedClicked = new ColumnClickEventHandler(lv_Click);
}
public MyExtender(IContainer parent) : this() { parent.Add(this); }
public bool CanExtend(object extendee) {
return extendee is ListView;
}
public bool GetListViewClickFeedback(ListView lv) {
if(listviews.ContainsKey(lv)) {
return listviews[lv];
}
return false;
}
public void SetListViewClickFeedback(ListView lv, bool implement) {
if(!listviews.ContainsKey(lv)) {
listviews.Add(lv, implement);
}
if(implement) {
lv.ColumnClick += extendedClicked;
listviews[lv] = true;
} else {
lv.ColumnClick -= extendedClicked;
listviews[lv] = false;
}
}
void lv_Click(object sender, ColumnClickEventArgs e) {
OnListViewClick(new ListViewClickedEventArgs(e.Column));
}
}
}

now when you drag the extender on the form, you need to wire up the ListViewClick in the form (this will be sent when you click), I suppose you could implicitly set this up in the SetListViewClickFeedback method as well using one of the designer services, but this is just a quick sample.

not sure if this helps, but hopefully it gets you in the right direction.
MadHatter at 2007-11-9 11:30:42 >
# 8 Re: extender callback
Thanks!
That got the event onto the MyExtender in the IDE. But is it possible to get it listed with the ListView so that each one has a different delegate ?
FoodBard at 2007-11-9 11:31:35 >
# 9 Re: extender callback
I'm sure there is, I've never tried having an extender that provided an event to in the property grid of the designed object though.
MadHatter at 2007-11-9 11:32:44 >