Click here to Skip to main content
15,915,501 members
Home / Discussions / C#
   

C#

 
GeneralIMalloc vs Release Pin
Tristan Rhodes16-Mar-04 6:20
Tristan Rhodes16-Mar-04 6:20 
GeneralRe: IMalloc vs Release Pin
Jeremy Kimball16-Mar-04 6:28
Jeremy Kimball16-Mar-04 6:28 
GeneralRe: IMalloc vs Release Pin
Judah Gabriel Himango16-Mar-04 8:44
sponsorJudah Gabriel Himango16-Mar-04 8:44 
GeneralRe: IMalloc vs Release Pin
Jeremy Kimball16-Mar-04 9:03
Jeremy Kimball16-Mar-04 9:03 
GeneralRe: IMalloc vs Release Pin
Judah Gabriel Himango16-Mar-04 10:05
sponsorJudah Gabriel Himango16-Mar-04 10:05 
GeneralENGLISH! My grammer sucks :P Pin
Tristan Rhodes16-Mar-04 11:03
Tristan Rhodes16-Mar-04 11:03 
GeneralRe: ENGLISH! My grammer sucks :P Pin
Judah Gabriel Himango16-Mar-04 11:31
sponsorJudah Gabriel Himango16-Mar-04 11:31 
GeneralDelegates and EventHandlers Pin
MrEyes16-Mar-04 5:57
MrEyes16-Mar-04 5:57 
Before I get going here, allow me to apologise for this thread not making much sense.

ok now thats out of the way, let me try and explain whats going on here.

I have a normal C# form that contains a data grid (DevExpress XtraGrid, although I dont think that is relevant). The configuration for the grid is held in an XML file, so when the form loads it reads the XML data and via a configuration class it configures the grid with all the require parameters etc etc.

The problem that I have is that I need to handle grid events and these events must reside within the form class and not the configuration class.

To overcome this problem I have created a delegate, in the form I create a list of the required delegates and send them to the configuration class when it is called.

so this is what we have so far :

public class ControlVars
{
	public delegate void gridEvents ( object sender, EventArgs e );
}

public class Initialisation
{
	public data[] InitGrid(XmlDocument configXdoc, Hashtable EventDelegates)
	{
		//code to cycle through the XML config file
		...snip (case data comes from the XML file)
		case "xmldata_combobox":
			//create the control
			//set whatever parameters
			//set the event handler for this control
			myComboBox.SelectedIndexChanged += ???????????????????????
		
		break;
		case "xmldata_text":
			//create the control
			//set whatever parameters
			//set the event handler for this control
			myText.TextChanged += ???????????????????????		
		break;
		...snip
		
	}
}

public class MyForm
{
	//event handlers
	private ComboBox_GridEvent1....//event code
	private Text_GridEvent2....//event code
	...

	private void myForm_Load(object sender, System.EventArgs e)
	{
		//create a hashtable containing grid event delegates
		Hashtable EventDelegates = new Hashtable();
		EventDelegates.Add("comboboxselected_event", new ControlVars.gridEvents(ComboBox_GridEvent1));
		EventDelegates.Add("textchanged_event", new ControlVars.gridEvents(text_GridEvent2));
		
		//Get the config XML data
		...snip
		
		//Initialise the grid
		Initalisation init = new Initialisation();
		GridData[] gData = init.initGrid(configXdoc, EventDelegates);
		
		//pass the initialised grid data to the grid
		myGrid.DataSource = gData;
  }


}


Where I am stuck is what to do when I need to set the event handler for the item I am generating, I have the Hashtable that contains the delegates and I have tried to set the event handler to use:

myControl.MyEvent += new EventHandler(eventDelegates["event_description"]);


And variations thereof but I am not getting anywhere.

Hopefully that will make sense to somebody who can put me on the right track.


post.mode = postmodes.signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
GeneralRe: Delegates and EventHandlers Pin
Jeremy Kimball16-Mar-04 6:31
Jeremy Kimball16-Mar-04 6:31 
GeneralRe: Delegates and EventHandlers Pin
MrEyes16-Mar-04 7:45
MrEyes16-Mar-04 7:45 
GeneralRe: Delegates and EventHandlers Pin
Jeremy Kimball16-Mar-04 9:04
Jeremy Kimball16-Mar-04 9:04 
GeneralRe: Delegates and EventHandlers Pin
Heath Stewart16-Mar-04 6:38
protectorHeath Stewart16-Mar-04 6:38 
GeneralActive Directory hotswap policy Pin
UltraKev16-Mar-04 4:41
UltraKev16-Mar-04 4:41 
GeneralRe: Active Directory hotswap policy Pin
Heath Stewart16-Mar-04 5:02
protectorHeath Stewart16-Mar-04 5:02 
GeneralRe: Active Directory hotswap policy Pin
UltraKev16-Mar-04 5:14
UltraKev16-Mar-04 5:14 
GeneralRe: Active Directory hotswap policy Pin
Heath Stewart16-Mar-04 5:25
protectorHeath Stewart16-Mar-04 5:25 
Generalmanaged c++ vs. c# Pin
Anonymous16-Mar-04 4:38
Anonymous16-Mar-04 4:38 
GeneralRe: managed c++ vs. c# Pin
Judah Gabriel Himango16-Mar-04 4:56
sponsorJudah Gabriel Himango16-Mar-04 4:56 
GeneralRe: managed c++ vs. c# Pin
Heath Stewart16-Mar-04 5:06
protectorHeath Stewart16-Mar-04 5:06 
GeneralRe: managed c++ vs. c# Pin
Judah Gabriel Himango16-Mar-04 5:38
sponsorJudah Gabriel Himango16-Mar-04 5:38 
GeneralRe: managed c++ vs. c# Pin
Heath Stewart16-Mar-04 4:59
protectorHeath Stewart16-Mar-04 4:59 
GeneralRe: managed c++ vs. c# Pin
Nemanja Trifunovic16-Mar-04 5:17
Nemanja Trifunovic16-Mar-04 5:17 
GeneralRe: managed c++ vs. c# Pin
Jeremy Kimball16-Mar-04 6:34
Jeremy Kimball16-Mar-04 6:34 
GeneralDllImport Without Attribute Pin
Werdna16-Mar-04 4:06
Werdna16-Mar-04 4:06 
GeneralRe: DllImport Without Attribute Pin
Heath Stewart16-Mar-04 4:19
protectorHeath Stewart16-Mar-04 4:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.