|
Jordanwb wrote: It also overrides ToolStripMenuItem' ToString method via "new public string ToString () {}".
That is a contradiction, it is either override or new. And it seems you want override.
Have it return a constant (say return "aha";) to convince yourself it gets called.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Tried "public override string ToString ()" and it doesn't work either. Still wouldn't explain the NullReferenceException.
|
|
|
|
|
The NullRefExc has nothing to do with the .NET version, it indicates there is a bug in
your code. Either single-step through it, or look at the Exception.ToString() output
to pinpoint the exact line that causes it.
And publish the Exception as well as (the relevant parts of) your code here if you want
detailed help.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I'm no longer getting the NullReferenceException for some strange reason, but if I use "new public string ToString ()" or "public override string ToString ()", text isn't showing up in the ComboBox.
|
|
|
|
|
I need to see some code in order to have a chance helping you any further.
Did you single-step the relevant code? did you look at intermediate results?
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Okee Dokey.
Category class (irrelevant code ommitted)
<code>
public class Category : ToolStripMenuItem
{
public Category(int id, string name)
{
this.id = id;
this.Text = name;
this.sub_items = new List<Program>();
}
public override string ToString()
{
return this.Text;
}
}
</code>
Where I add the Categories to the ComboBox:
<code>
public partial class RemoveCategory : Form
{
public RemoveCategory(AccessReader database, HashMap<int, Category> categories)
{
InitializeComponent();
this.database = database;
this.categories = categories;
this.cmb_categories.Items.AddRange(categories.ToArray());
this.cmb_categories.SelectedIndex = 0;
}
}
</code>
The HashMap class is a class that I made that maps a key (in this case int) to a value (in this case Category), the ToArray() method returns an array of Categories that contain all the values in the HashMap. In the callback for when the button is clicked, the SelectedItem property of the ComboBox is no long returning null but is returning an object which is casted into a Category.
|
|
|
|
|
Hi,
you have a problem in the button click handler, but you don't show its code.
you explain about HashMap but the code you show does not use it.
you had null exceptions but they are gone without any explanation? or are they still present?
are you sure you want to be successful in software development?
start by giving all relevant code, exactly as it is, and all the symptoms, and please
combine them in a single message, to increase the possibility they describe a consistent
situation.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Luc Pattyn wrote: you have a problem in the button click handler, but you don't show its code.
you explain about HashMap but the code you show does not use it.
you had null exceptions but they are gone without any explanation? or are they still present?
are you sure you want to be successful in software development?
start by giving all relevant code, exactly as it is, and all the symptoms, and please
combine them in a single message, to increase the possibility they describe a consistent
situation.
It's hard to have a consistent solution if the program isn't acting consistantly (flashbacks to Java). The HashMap class is irrelevant to the problem. In the Button click event I am no longer getting the NullReferenceException.
Here's the button click event:
<br />
private void btn_okay_Click(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
Category s = (Category)cmb_categories.SelectedItem;<br />
MessageBox.Show(s.ToString());<br />
}<br />
catch (NullReferenceException nre)<br />
{<br />
MessageBox.Show(nre.ToString());<br />
}<br />
}<br />
What is there to go wrong there on my end? Yesterday cmb_categories.SelectedItem was returning null, now it's not. I get a MessageBox saying "Office" or "Programming" like it should, so that would mean no NullReferenceException. The HashMap returned a proper array of Categories, no nulls whatsoever.
Also in the constructor I added this line directly after "this.cmb_categories.Items.AddRange(categories.ToArray());":
ComboBox.ObjectCollection oj = cmb_categories.Items;
oj.Count said 2, which is correct. I place a breakpoint at the line mentionned above and it reaches that line I hover over oj, then hover over "Non Public Members", then over "innerList" it shows two objects both of type Category, and the proper ToString() method of the two categories were called.
Luc Pattyn wrote: you explain about HashMap but the code you show does not use it.
Yes I did, check the constructor's parameters. I called it a HashMap because that's what it's called in Java. Until today I learned that C# has one in System.Collections.Generic, it's called a Dictionary.
Luc Pattyn wrote: are you sure you want to be successful in software development?
Who said I wanted to go into software development? I plan on going into PHP based website design.
Oh BTW, I had a similar problem with a ListBox I believe. I had one form with said ListBox, I had two different classes extend that form. On one form the add worked whereas on one class it did not. In the parent form I had a method to do an invoke to avoid the CrossThreadedCallException. Both child classes used the same method. Then for some reason the second started working for no reason whatsoever. Was that my fault? I've seen this happen dozens of times: code just starts working with everyone scratching their heads.
modified on Sunday, April 20, 2008 10:13 PM
|
|
|
|
|
Hi,
I missed the relevance of HashMap due to your way of publishing code; instead of showing
real < and > signs you insert something that results in escape sequences, and instead
of using real PRE tags you use fake CODE tags; this makes reading your stuff rather hard.
If the combobox does not show the right stuff and it gets populated by an
AddRange(categories.ToArray()) then either your observation is wrong or
the ToArray() method does not function properly, which is what I expect. I don't know
what your ToArray() returns, but combobox expects either a list of strings, or a list
of items that can be displayed by calling their ToString().
Just logging the ToArray() result should pinpoint the problem.
I do not like your attitude on things that first don't work, then suddenly do work.
If "code just starts working with everyone scratching their heads" then something is
definitely wrong; it could be your PC hardware or software; more likely it is a
lack of quality and robustness in your code, something that you must learn by
investigating problems until you SOLVE them, and not until they happen to disappear.
I leave this thread here and now, its length exceeds its weight.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Luc Pattyn wrote: I missed the relevance of HashMap due to your way of publishing code; instead of showing
real < and > signs you insert something that results in escape sequences, and instead
of using real PRE tags you use fake CODE tags; this makes reading your stuff rather hard.
Whoa there, that was the forum. As soon as I put in the < and > the forum changed them to the HTML escape characters.
Luc Pattyn wrote: If the combobox does not show the right stuff and it gets populated by an
AddRange(categories.ToArray()) then either your observation is wrong or
the ToArray() method does not function properly, which is what I expect. I don't know
what your ToArray() returns, but combobox expects either a list of strings, or a list
of items that can be displayed by calling their ToString().
The AddRange method accepts an array of objects not strings. I did:
Category[] all_categories = categories.ToArray (); and it returned an array of Categories like I expected.
Luc Pattyn wrote: I do not like your attitude on things that first don't work, then suddenly do work.
Well sorry for telling it like it is. That's what happened.
Luc Pattyn wrote: If "code just starts working with everyone scratching their heads" then something is
definitely wrong; it could be your PC hardware or software; more likely it is a
lack of quality and robustness in your code, something that you must learn by
investigating problems until you SOLVE them, and not until they happen to disappear.
It's hard for simple, incredibly short code to be inefficient and unrobust. It's also hard for it to be my fault when it is adding them to the comboBox but not showing the actual text in the comboBox.
Luc Pattyn wrote: I leave this thread here and now, its length exceeds its weight.
Okay fine.
Maybe if I retype everything a fourth time it will magically start working.
|
|
|
|
|
Hi,
I started to use c# for sometime and I don't have any certification of Microsoft. Can anyone please recommend the first certificate for me. thk in advance.
|
|
|
|
|
You need to decide what you want to focus on in the industry. If you are into C# you probably want to do the VS2005 or VS2008 training which include either Microsoft Certified Professional Developer and Microsoft Professional Technology Specialist. Within those two it breaks down whether you want to be a web developer, Windows developer and so forth. I have posted a Microsoft link that will probably help. Once you know which route you want to take then start at the lowest level class.
http://www.microsoft.com/learning/mcp/certifications.mspx[^]
|
|
|
|
|
You can start with 70-536 Application Foundation. It's for .Net 2.0.
If you just started C# you should wait and read a few books since this exam covers a lot of things.
|
|
|
|
|
Hey everyone
I can successfully use SendInput to send mouse clicks, but I am having trouble getting it to work with sending keys. Please can someone tell me where I have gone wrong
public struct KEYDBINPUT
{
public Int16 wVk;
public Int16 wScan;
public Int32 dwFlags;
public Int32 time;
public Int32 dwExtraInfo;
public Int32 __filler1;
public Int32 __filler2;
}
public struct INPUT
{
public Int32 type;
public KEYDBINPUT ki;
}
[DllImport("user32")]
public static extern int SendInput(int cInputs, ref INPUT pInputs, int cbSize);
public const int INPUT_KEYBOARD = 1;
public const int KEYEVENTF_KEYUP = 0x0002;
public void sendKey(short key)
{
INPUT inputDown = new INPUT();
inputDown.type = INPUT_KEYBOARD;
inputDown.ki.dwFlags = 0;
INPUT inputUp = new INPUT();
inputUp.type = INPUT_KEYBOARD;
inputUp.ki.dwFlags = KEYEVENTF_KEYUP;
inputDown.ki.wVk = key;
SendInput(1, ref inputDown, Marshal.SizeOf(inputDown));
inputUp.ki.wVk = key;
SendInput(1, ref inputUp, Marshal.SizeOf(inputUp));
}
Thanks a lot
Luke
|
|
|
|
|
* Use the LayoutKind.Sequential structure attribute.
* You should fill the dwExtraInfo member (set it to the value returned by GetMessageExtraInfo ).
* The scan code should be set to the value returned by MapVirtualKey applied to the virtual key code.
* Depending on whether it's an extended key, you should also specify the KEYEVENTF_EXTENDEDKEY flag.
* You should use IntPtr for pointers. Using Int32 will break compatibility of your application with 64-bit operating systems.
I recommend to use the definitions on P/Invoke.net: SendInput[^]
Best regards
Dominik
|
|
|
|
|
hi
i want to create app that give it my table(s) of database (connect to db), and it generate a class as my table's name, with all filed(s) and some method(s) and .... Automatically, but how to do ?
i don't use other autoGeneration tools such as SqlMetal.exe to create entity class automatically, i want to write this tools mySelf.
thanks
|
|
|
|
|
Most developers do this - they sometimes end up as complete frameworks, ironspeed comes to mind.
Think about where you will get you table information (system information views in SQL Server)
Build you DAL for getting to the DB
Build a sample class you want to use as a template (using your DAL).
What is your delivery platform (usually winforms)?
Build your app to get and display the databases and tables (usually in a tree)
Allow drill down to column and then attributes.
Now use string manipulation to build the class based on your template
Decide if you want to copy/paste the class into the IDE or you want to interact directly with the project
Build it - and you will have a MUCH deeper understanding of your database, application and many technologies when you are finished. BTW you will probably never "finish" this project. I'm still tweaking mine which originated in VB5.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
On my form I have a NotifyIcon which has a ContextMenuStrip of ToolStripMenuItem's. Each of the ToolStripMenuItem has a List of ToolStripMenuItem which has two items, like so:
Notify Icon:
-ContextMenuStrip:
--Item1:
---SubItem1:
----Launch
----Remove
---SubItem2:
----Launch
----Remove
--Item2:
---SubItem1:
----Launch
----Remove
When I click on the notify icon, then hover any of the sub items it shows up in the taskbar. Is there some way to not show in the taskbar but still show when I hover over an item?
|
|
|
|
|
|
Hi guys. I'm writing a little program to interact with a device connected to the COM port and I need to assign different commands(from the device) to specific methods. I've created a single delegate
public delegate void Delegate_Name ()
Every device command is assigned to a delegate/event of Delegate_Name type and store inside a Dictionary object. I can serialize to xml a Dictionary, but when I get to saving the events I received the well known and general exception:
[System.InvalidOperationException] = {"There was an error generating the XML document."}
I'm able to store (serialize) all the information to xml files but I'm unable to save the delegates.
Is there a way to do this?
|
|
|
|
|
You can't serialize delegates. Actually you can't save them in any way at all. They are pointers to the memory location of the method, so they only have a meaning while the same program is still running.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I'm happy to inform you that I managed to serialize a delegate/event using reflection.
|
|
|
|
|
Do you have control to input IP address version 6 ?
|
|
|
|
|
I am not sure whether a control would be available or not.
However, you can easily create one textbox with the validations as required in a 128 bit IP Address.
Best Regards,
Sam Xavier
www.componentone.com
|
|
|
|
|
hi there ,
I am developing windows service using C#, and finally I want to create a setup file for it to be deployed to the users ,
I need to learn that , and also there is some tasks I need it to change somethings or add some informations on the machine it is installed on , how can I use batch file to achieve that and how can do it within the installation process!!!
How can create setup file for the user which should do every thing (including the changes I need)
please help
thanks in advance
There is always something to learn
|
|
|
|