|
if (control.InvokeRequired)
control.Invoke(...., .....);
else
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
Thanks for the hint. But I still have some further question.
The Invoke require a delegate as the arguement. What I want to ask is, if I dynamically create a number of buttons when a delegate callback triggered, can I set those buttons' parent to the original form?
|
|
|
|
|
The simplest solution is to marshal to call to the correct thread when the delegate is invoked:
class CA : System.Windows.Forms.Form
{
...
protected void OnMyEvent(int nCount)
{
if (this.InvokeRequired)
{
this.Invoke(new OnMyEventHandler(this.OnMyEvent));
}
else
{
for ( int i = 0; i < nCount; i ++ )
{
Button btn = new Button();
btn.Parent = this;
btn.Location = new Point( 100 + i * 100, 10 );
btn.Show();
}
}
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Hi, I am new to C# and this message board, so I would appreciate any help I can get. I am writing and MDI application, where I have the parent screen split in two areas (with size of the area on the left about 20% of the MDI parent). The area on the left will be the navigation screen and on the right will display the window that results from user action taken on the left. I am trying to get the windows on the right to display the maximum size of its alloted area and I thought I can do this by adding it to a panel. Is it possible to add a form to a panel and if so can any provide some code on doing this. If not, is there some kind of container to restrict the child form size to its alloted area. Thanks.
|
|
|
|
|
Someone who wrote a book[^] about .NET interop has released a free tool[^] to monitor type marshaling inside the CLR. It takes advantage of .NET 1.1. It works on all machines, although Windows XP is required to show the balloon tooltips.
|
|
|
|
|
Clicking on the second link gives you a "Server error in / application."
Hawaian shirts and shorts work too in Summer.
People assume you're either a complete nut (in which case not a worthy target) or so damn good you don't need to worry about camouflage...
-Anna-Jayne Metcalfe on Paintballing
|
|
|
|
|
The tool link works for me.
For others if you don't know about Adam Nathan, he is CLR Test Lead.
Don't and drive.
|
|
|
|
|
Kant wrote:
For others if you don't know about Adam Nathan, he is CLR Test Lead.
And a freaking god when it comes to Interop.
Hawaian shirts and shorts work too in Summer.
People assume you're either a complete nut (in which case not a worthy target) or so damn good you don't need to worry about camouflage...
-Anna-Jayne Metcalfe on Paintballing
|
|
|
|
|
I bet he is Stephane's guru.
Don't and drive.
|
|
|
|
|
eh... who knows
|
|
|
|
|
Don't forget to read his blog[^] as well. Apparently, the new Application.EnableVisualStyles() method has a marshalling bug in it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
I am subscribed to it since day one. But quite honestly, I think I am gonna quit it altogether as I tend to think that as a "customer" I don't have to learn the intrinsics of an engine whose implementation is going to change anyway.
For any current problem, the work around is to write a dll and use a P/Invoke native call to bypass the CLR itself. It only takes an F-grade know-how to do so. I swallow a small raisin, leaving away all this crap.
|
|
|
|
|
I'm trying to educate myself on C# and .Net. I decided to try and use the techniques outlined by Marc Clifton ("Using XML to generate Menus") but to use it with a different UI tool kit along with extending the menus.xsd to support imagelists.
What I'm looking for is a method of taking an input name (of an imagelist or a method) passed in the xml definition or the menu and use that name to pass the actual object or method to the appropriate constructors etc.
I've found that I can find the appropriate MethodInfo information using reflection and can find the FieldInfo information for an imagelist but I can't seem to figure out how to use that information to accomplish my objective. I'm using the Crownwood Magic Library menus that have a MenuCommand constructor that will take an imagelist and index value for the menu image and will take an EventHandler for an OnClick event.
Is there a way to use the information retrieved form the reflection methods to set the event handler and to set the imagelist from the names passed in the xml.
Thanks for the help
Neil Lamka
neil@meetingworks.com
|
|
|
|
|
I beleave you are on the wright track you just need to use the
typeof( YourType ).GetMethod( "MethodName", BindingFlags.Public ).Invoke( objToCallInvokeOn, new object[](arg1, arg2, arg3} );
The BindingFlags is just that there flags so you can use | operator.
The args can be null new object[]{null} or null will work I beleave.
There are a few different ways and method overloads that is avaliable.
|
|
|
|
|
Thanks for the pointer.
If I use this method then I'm assuming that in my DLL that handles reading the XML definitions for menus and all that I'd have
1) Set an "OnClick" event handler internal to my DLL
and then
2) When processing the OnClick event figure out the real target menthod that should process the event and use the Invoke as you described.
Is there any way to set the event handler for the menu item so as to bypass having to handle the event and route it? I'd like to get out of the way and just wire the menu directly to the desired handler. I was hoping that once I found the MethodInfo for the target method I would be able to set the menu event handler directly. Or is that what your note allows me to do and I just did not understand.
Thanks
Neil
Neil Lamka
neil@meetingworks.com
|
|
|
|
|
Sorry it took so long to get back. I hate to say it but I dont fully
understand what it is you need to do. Just a little more info on what
you need to do and maybe I can help some more.
Bo Hunter
|
|
|
|
|
Ok, Let me try again.
What I'd like to be able to do is (from a class in a managed DLL) to take a method name from a file, create a menu item and set the "OnClick" event to use that method.
What I have been able to figure out is how to set an onclick event handler that resides in my DLL and then to use Invoke to route the event to the desired handler within the application. I was looking for a direct way to wire the event handler to the menu item without the intermediate handling.
I have the MethodInfo for the desired (real) event handler but don't see any way to use that to set the OnClick event using that information.
An example would be something like
<xmlstuff>
<menuitem>
&File
<onclick>My_Handler
....
in the DLL
string caption = ... get the caption from the xml
string onclick = ... get the handler from the xml
MethodInfo mi = ... get the MethodInfo for "My_Handler" (from onclick)
//* I'm using the MagicLibrary .. which is where the MenuCommand lives
MenuCommand mc = new MenuCommand( caption );
mc.Click += ??? using the MethodInfo from above.
What I do have is the above but with
mc.Click += new EventHandler(menu_Click); //menu_Click is my internal handler)
private void menu_Click(object sender, System.EventArgs e)
{
MethodInfo mi = .. get the Method info for the real handler
....
mi.Invoke(_callingInstance, args);
....
}
So..the .Net of what I'm trying to do is to use what I can find out from Reflection to wire a menu item directly to the target event handler without having to use Invoke and this event redirection.
Hope this helps
Neil Lamka
neil@meetingworks.com
|
|
|
|
|
1.How to get the index (int) from ImageList.Images?(this returns System.Drawing.Image)
2. Right click on Solution -> Add -> Add New Item. In that dialog, Is the "OPEN" button a custom control? Is it available via Toolbox?
Don't and drive.
|
|
|
|
|
Can anyone help me get my datagrid to update it's data?
I’ve populated a datagrid with the contents of a table from an access database, but the problem I’m running into is when I change a value in the grid it’s not being saved/updated/deleted in the database. Has anyone ever done anything like this before? I've seen some examples in sql server and one or two things in access from the web but none of them seem to work correctly.
Thanks
|
|
|
|
|
Manster wrote:
Can anyone help me get my datagrid to update it's data?
Looks like nobody answered your earlier post.
Anyway I will try.
Did you check the RowState property "DataRowState.Modified" value?
Don't and drive.
|
|
|
|
|
I've tried using the OleDB objects but haven't found a way to get the grid to update it's data successfully. I haven't tried the DataRowState.Modified property. Are you familiar with datagrids? I guess they are not as common as I thought.
|
|
|
|
|
Post your code snippet, so that others can identify the problem.
Is the data grid on a WebForm or Windows Form?
Don't and drive.
|
|
|
|
|
My datagrid is on a windows form. This is the code that is in the m_DataGrid_Validate() grid event when you close the application once some data has been changed in the grid.
DataSet dsUpdate = m_MyDataSet.GetChanges();
OleDBDataAdapter dataAdapter = new OleDBDataAdapter ("Update Authors set ...", m_sConn);
OleDBCommandBuilder cb = new OleDBCommandBuilder(dataAdapter);
dataAdapter.UpdateCommand = cb.GetUpdateCommand();
dataAdapter.Update(dsUpdate, "Authors");
dsUpdate.AcceptChanges();
|
|
|
|
|
Try this:
change the button1 to your update button name
dataSet21 to your DataSet name.
oleDbDataAdapter1 to your DataAdapter name.
Products to your table name.
I used Northwind database via MSDE and it worked.
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
if (dataSet21.HasChanges())<br />
{<br />
try<br />
{<br />
int nModified;<br />
nModified = oleDbDataAdapter1.Update(dataSet21.Products);<br />
string strOutput;<br />
strOutput = "Modified " + nModified + " products(s)";<br />
MessageBox.Show(strOutput, "Update succeeded!", <br />
MessageBoxButtons.OK, MessageBoxIcon.Information);<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message, "Update failed!",<br />
MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
}<br />
}<br />
else<br />
{<br />
MessageBox.Show("No changes to submit!", "SubmitChanges",<br />
MessageBoxButtons.OK, MessageBoxIcon.Information);<br />
}<br />
}
Don't and drive.
|
|
|
|
|
I just want to make sure I'm on the same page as you ( I'm new to C# ). You added oleDbDataAdapter1 to the form and by adding this object studio creates your insert, update, and delete statements for you? The dataSet21 dataset is the same one you used to populate the grid in the first place? So just make the changes you mentioned and that's it?
Thanks for all your help!
|
|
|
|