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]

# 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.
# 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.
# 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.