|
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!
|
|
|
|
|
Manster wrote:
I'm new to C#
Me too.
Manster wrote:
You added oleDbDataAdapter1 to the form and by adding this object studio creates your insert, update, and delete statements for you?
Yep. Using "Data Adapter Configuration Wizard" (by dragging
OleDbDataAdapter onto the form)
Manster wrote:
The dataSet21 dataset is the same one you used to populate the grid in the first place?
Yes. I generated the dataset via adapter properties, where I clicked the "Generate Dataset" or You can do via "Data" menu -> "Generate Dataset"
Select "New" and select your table.
Is that what you are looking for? or Am I mumbling something else?
Don't and drive.
|
|
|
|
|
Yea I think that's it. I declared a dataset object in my code, I didn't add it to the form through the generate option. Hopefully that will do the trick. I haven't had a chance to test it yet.
Thanks for all your help!
|
|
|
|
|
For some reason I can't get your changes to work. Is their any chance you can send me your demo project?
Thanks
|
|
|
|
|
I have a client who wants to upgrade their office to a windows environment, but they want it to be as similar as an old dos program they've been using since the year dot.
Because of this, I have to make a program that they can navigate entirely with the keyboard. Currently I am stuck trying to work out how to make the menus either get the focus (so they can use the arrow keys to navigate), or make a menu open just from a keypress. I have tried calling the MenuItem.Select or MenuItem.PerformClick method, but neither of these seems to bring the focus to the menu.
Does anyone have an idea where to look for this? - I have seen hundreds of articles on how to create a menu item when i searched, but none to simply open a menu.
|
|
|
|
|
1. In the menu item, define the Text with ampersand
ex: &File.
Then you can use the shortcut ALT+F to get to this menu
2. Look after accelerators in MSDN
|
|
|
|
|
Unfortunately that won't work for this program. Because of the way the dos program was structured I need to be able to press a single key (in this case the left or right arrow) to open the menu's. Most of the staff that use this program might be able to turn a computer on on a very good day and the owner doesn't want to have to retrain them (hah) to learn to use a new program.
What I am looking for is the equivalent of menu.open or menu.focus (as such), ie: how can I call the equivalent of a mouse click on a menu in code to make the menu open? MenuItem.PerformClick would work, if I knew how to tell the menu to open.
|
|
|
|
|
action at property window:
for windows form has an DataGrid with set to ReadOnly. Then, no more action to modify the ReadOnly value to false ("Invalid Property, Object reference not set to an instance of an object") ?!?!
but when u try to write code for perform below action, it's ok.
and another way: open code window, expand the node (region) "Windows Form Designer generated code" (M$ auto generated code for your visual interface), navigate to the DataGrid definition and simply set the ReadOnly property to false.
Is here any my mistake?
|
|
|
|