473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

I want to a event method to be called in the a form.

Hello!!

Hello Victor!

I use a product called flygrid to create grid tables.
In many of my forms I create such grid tables.
Some columns in these grid tables is of type drop down list where I can
select a value from the list.

Below I have some code which exist in a file named StringClass.cs
There are two classes in the code StringClass and StringClassEditor.

When the drop down list is about to open method EditValue is called and a
ListBox is created and filled with values see the code below.
When a value is selected from the drop down list method SelectedIndexChanged
is called see code below.

Now to my problem I don't want to put all code that exist in StringClass.cs
in every form I use.
What I do want to do if it's possible is to have the event method in this
case SelectedIndexChanged to be put in the form class.
So for example when I have form named form1 and select a value from a drop
down list that exist in a flygrid an event metod that exist in the form1
should be called. For example method SelectedIndexChanged.

One of my problems here is how do I modify class StringClassEditor so the
event metod can be called which exist in my form.

[TypeConverter(typeof(StringClass.StringClassConver ter))]
[Editor(typeof(StringClass.StringClassEditor), typeof(UITypeEditor))]
public class StringClass
{
private string strValue;
protected ArrayList valuesList;

public StringClass(string value)
{ strValue = value; }

public StringClass()
{ strValue = null; }

public StringClass(string value, string[] values) : this(value)
{ valuesList = new ArrayList(values); }

public StringClass(string value, ArrayList values) : this(value)
{ valuesList = values; }

public class StringClassEditor : UITypeEditor
{
private IWindowsFormsEditorService wse = null;
private StringClass editedSc = null;
private string originalValue = null;

private bool StringClassHasValueList(StringClass sc)
{ return sc != null && sc.ValuesList.Count > 0; }

public override System.Drawing.Design.UITypeEditorEditStyle
GetEditStyle(ITypeDescriptorContext context)
{ return
System.Drawing.Design.UITypeEditorEditStyle.DropDo wn; }

public override object EditValue(ITypeDescriptorContext
context, IServiceProvider provider, object value)
{
Type type = value.GetType(); //get type for value

if (StringClassHasValueList(( StringClass ) value))
{
wse = (IWindowsFormsEditorService )
(provider.GetService(typeof(IWindowsFormsEditorSer vice)));
if (wse != null)
{
ListBox lb = new ListBox();
editedSc = (StringClass) value;
originalValue = editedSc.StrValue;
string[] values = (string [])
(editedSc.ValuesList.ToArray(typeof(string)));

lb.Items.AddRange(values);
int selectedIndex = editedSc.StrValue !=
null ? lb.Items.IndexOf(editedSc.StrValue) : -1;
if (selectedIndex != -1)
lb.SelectedIndex = selectedIndex;

lb.KeyDown += new
KeyEventHandler(ListBox_KeyDown); //anger en delegate
lb.SelectedIndexChanged += new
EventHandler(ListBox_SelectedIndexChanged);
lb.Click += new
EventHandler(ListBox_Click);

wse.DropDownControl(lb);
wse = null;
return editedSc;
}
}
return base.EditValue (context, provider, value);
}

private void ListBox_KeyDown(object sender, KeyEventArgs e)
{
if (wse != null && (e.KeyCode == Keys.Escape ||
e.KeyCode == Keys.Return))
{
if (e.KeyCode == Keys.Escape)
editedSc.StrValue = originalValue;//return
to original value
wse.CloseDropDown();
}
}

private void ListBox_Click(object sender, EventArgs e)
{ wse.CloseDropDown(); }

private void ListBox_SelectedIndexChanged(object sender,
EventArgs e)
{
ListBox lb = (ListBox) sender;
editedSc.StrValue = (string)lb.SelectedItem;
}
}

//Tony
Apr 19 '06 #1
1 2329
VJ
You will have to do a delegate and wrap event around the delegate, make the
event public on the grid.. and make sure your Grids in the Form subscribe to
the events... Even before you have to write your own dervied grid... see
below.. The code is to give you a idea of flow.... I hope you can implement
this to your needs...

namespace MyNameSpace
{
public MyGrid : System.Windows.Forms.DataGrid
{
public event MySelectedIndexChangeEventHandler
mySelectedEvent=null;
private void MyGrid_selectedIndexChanged(object sender, EventArgs e)
{
if ( mySelectedEvent!= null )
{
mySelectedEvent(this, new MySelectedIndexEventArgs
("test"));
}
}

}

public delegate void MySelectedIndexChangeEventHandler (Object sender,
MySelectedIndexEventArgs e);

public class MySelectedIndexEventArgs : EventArgs
{
private string _myArg;

public string myArg
{
get { return _myArg ; }
set { _myArg = value ; }
}

public MySelectedIndexEventArgs ( string MyArg1)
{
_myArg = MyArg1;
}
}

}

' In your Form

private void myTest()
{
myGrid1.mySelectedEvent+=new
System.EventHandler(this.myNewSelectedEvent);
}

private void myNewSelectedEvent(object sender, EventArgs e)
{
// e.myArg will give "test"
}

VJ

"tony" <jo*****************@telia.com> wrote in message
news:eN**************@TK2MSFTNGP03.phx.gbl...
Hello!!

Hello Victor!

I use a product called flygrid to create grid tables.
In many of my forms I create such grid tables.
Some columns in these grid tables is of type drop down list where I can
select a value from the list.

Below I have some code which exist in a file named StringClass.cs
There are two classes in the code StringClass and StringClassEditor.

When the drop down list is about to open method EditValue is called and a
ListBox is created and filled with values see the code below.
When a value is selected from the drop down list method
SelectedIndexChanged
is called see code below.

Now to my problem I don't want to put all code that exist in
StringClass.cs
in every form I use.
What I do want to do if it's possible is to have the event method in this
case SelectedIndexChanged to be put in the form class.
So for example when I have form named form1 and select a value from a drop
down list that exist in a flygrid an event metod that exist in the form1
should be called. For example method SelectedIndexChanged.

One of my problems here is how do I modify class StringClassEditor so the
event metod can be called which exist in my form.

[TypeConverter(typeof(StringClass.StringClassConver ter))]
[Editor(typeof(StringClass.StringClassEditor), typeof(UITypeEditor))]
public class StringClass
{
private string strValue;
protected ArrayList valuesList;

public StringClass(string value)
{ strValue = value; }

public StringClass()
{ strValue = null; }

public StringClass(string value, string[] values) : this(value)
{ valuesList = new ArrayList(values); }

public StringClass(string value, ArrayList values) : this(value)
{ valuesList = values; }

public class StringClassEditor : UITypeEditor
{
private IWindowsFormsEditorService wse = null;
private StringClass editedSc = null;
private string originalValue = null;

private bool StringClassHasValueList(StringClass sc)
{ return sc != null && sc.ValuesList.Count > 0; }

public override
System.Drawing.Design.UITypeEditorEditStyle
GetEditStyle(ITypeDescriptorContext context)
{ return
System.Drawing.Design.UITypeEditorEditStyle.DropDo wn; }

public override object EditValue(ITypeDescriptorContext
context, IServiceProvider provider, object value)
{
Type type = value.GetType(); //get type for value

if (StringClassHasValueList(( StringClass ) value))
{
wse = (IWindowsFormsEditorService )
(provider.GetService(typeof(IWindowsFormsEditorSer vice)));
if (wse != null)
{
ListBox lb = new ListBox();
editedSc = (StringClass) value;
originalValue = editedSc.StrValue;
string[] values = (string [])
(editedSc.ValuesList.ToArray(typeof(string)));

lb.Items.AddRange(values);
int selectedIndex = editedSc.StrValue !=
null ? lb.Items.IndexOf(editedSc.StrValue) : -1;
if (selectedIndex != -1)
lb.SelectedIndex = selectedIndex;

lb.KeyDown += new
KeyEventHandler(ListBox_KeyDown); //anger en delegate
lb.SelectedIndexChanged += new
EventHandler(ListBox_SelectedIndexChanged);
lb.Click += new
EventHandler(ListBox_Click);

wse.DropDownControl(lb);
wse = null;
return editedSc;
}
}
return base.EditValue (context, provider, value);
}

private void ListBox_KeyDown(object sender, KeyEventArgs e)
{
if (wse != null && (e.KeyCode == Keys.Escape ||
e.KeyCode == Keys.Return))
{
if (e.KeyCode == Keys.Escape)
editedSc.StrValue =
originalValue;//return
to original value
wse.CloseDropDown();
}
}

private void ListBox_Click(object sender, EventArgs e)
{ wse.CloseDropDown(); }

private void ListBox_SelectedIndexChanged(object sender,
EventArgs e)
{
ListBox lb = (ListBox) sender;
editedSc.StrValue = (string)lb.SelectedItem;
}
}

//Tony

Apr 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
7
by: Joakim Braun | last post by:
Why doesn't the below code work? I'm trying to create a global object and set an event handler to one of its methods. The function is called, but the object's mTest property is undefined. ...
6
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all...
7
by: tony | last post by:
Hello! What is the differens if I use event handler onSizeChanged compare to using the other event handler MeltPracForm_SizeChanged. I see both as event handler is that right? I catch the event...
2
by: Franky | last post by:
Threre is a Form containing a usercontrol In the form's Load event it references a usercontrol property, say, zz The first showdialog(formx) causes 1 usercontrol_load event 2 form_load event...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
22
by: Zytan | last post by:
I have public methods in a form. The main form calls them, to update that form's display. This form is like a real-time view of data that is changing. But, the form may not exist (it is...
1
by: gbezas | last post by:
Hi All, I have added an event handler to redirect form.submit() to a newSubmit() method that I have defined (which does some additional processing before submitting the form). Additionally I...
6
by: tshad | last post by:
I was looking at a page that showed how to set up a custom event and it seems to work ok. But I am not sure how I would use it. How would I subscribe to it. There is actual action (such as...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.