|
Thanks mate. I'll go and read up on this if I can find a good article. Have not used it before. Or do you know of any article that can explain this? I haven't googled for one yet.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Dictionary<string, int> d = new Dictionary<string, int>();
void AddItem(string key)
{
if (!d.ContainsKey(key))
{
d[key] = 1;
}
else
{
++d[key];
}
}
Then you end up with a collection of keys, each is the name of an object you were counting ( I said use an enum, but I am simplifying this example ). So you iterate over the keys, and for each key, d[key] will return the number of items records for that key.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks mate. I will give this a shot and see what I come up with. I have found a few articles on the subject as well so will readup on them. Just don't have that much time left to deliver a working demo. And the Milestones changing everytime doesn't help me much either.
Thanks again.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
No worries - always glad to help. Dictionaries are an awesome container to get your head around, they have all sorts of uses. Hope it helped.
I know what you mean about shifting goals tho, we all get that.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
void AddItem(string key)
{
if (!objDict.ContainsKey(key))
{
objDict[key] = 1;
}
else
{
++objDict[key];
}
foreach (KeyValuePair<string, int> kvp in objDict)
{
txtboxTot.Text = ("Povince : " + kvp.Key + "\t" + kvp.Value);
}
}
You have two issues
1 - you're setting the textbox value inside the method that is adding them, so it's going to happen every time you add a value
2 - you set the textbox to be the last key/value pair you iterate over, because you do txtboxTot.Text = instead of txtboxTot.Text +=
Factor this code out to run when the loop that adds the values has ended, and have it add the values, instead of just showing the last one looped over. Also, use Environment.NewLine to put newlines in your textbox, if you want them ( make sure you set the textbox to be multiline )
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
THanks again mate. I got it working. One last question. Can I store multiple fields in the Dictionary? I.e. store the prov field which we are currently doing plus a few others and then itterate through them as well?
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
A dictionary maps one type to another type. Either type can be a class or struct, so you can store all the values you want in a class or struct and map to instances of it.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello,
I wrote a liitle program that displays a form with a button.
Once the button is pressed the program goes over the elemnts of some collection.
I would like to dispaly this elements on diffrent form, that would function as a simplified logger, on top of the existing form.
How can i do this ? must it be on a diffrent thread ? some code snippet would be great.
Thanks,
Berlus
|
|
|
|
|
your prolem is not clear from me. can you be more specific?
Thanks
Best Regards
-----------------
Abhijit Jana
"Success is Journey it's not a destination"
|
|
|
|
|
A second form would be on the same thread, just design it, and make an instance a member variable, then calling Show() would show it without stopping interaction with the main form. Show(this) would make it a proper child form. You can interact with it then via properties you expose, or use delegates to interact back to the main form
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello..
I have a ListView with CheckBoxes = TRUE. If I set FullRowSelect to TRUE, by DoubleClick (for example in Column 5) is the checkbox automatically set to TRUE or FALSE. How to avoid this ?
I want to use FullRowSelect (because of DoubleClick) but I don't want to change the state of CheckBox.
CheckBox state can only be changed, if user click on checkbox, not on "anywhere" in row.
Thx..
|
|
|
|
|
I assume you'd have to derive a class from teh control, handle the click and stop it from changing the state of the control if it's not in the right area.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi all,
I don't understand most of this "Indexer" code :
namespace UsingIndexers
{
class TestIndexers
{
private string[] MyStrings;
public TestIndexers()
{
MyStrings = new string[] { "This", "is", "an", "indexer", "test" };
}
// array like access
public string this[int index]
{
get
{
if (index < 0 || index >= MyStrings.Length)
{
throw new ArgumentOutOfRangeException();
}
return MyStrings[index];
}
set
{
if (index >= MyStrings.Length)
{
throw new ArgumentOutOfRangeException();
}
else
MyStrings[index] = value;
}
}
static void Main()
{
TestIndexers MyIndexer = new TestIndexers();
Console.WriteLine("index 1 is: {0}", MyIndexer[1]);
}
}
}
Especially I don't understand the use of indexers. Every individual element of MyStrings can be accessed through MyStrings[i]. WHy still additional code for indexing ?
And also this line of code is difficult for me :
public string this[int index]
What is the meaning of "this" ?
Any help is very much appreciated...
Many thanks in advance !!
Best regards, Steve
|
|
|
|
|
Steve Declerck wrote: Every individual element of MyStrings can be accessed through MyStrings[i]. WHy still additional code for indexing ?
But your data should be private. The indexer allows you to expose a public interface (don't confuse that with a C# interface ) for your private data. Of course, you could do away with an indexer and use a GetXXX(int index) method, but indexers are elegant. You are not limited to integers; you can also use other types for the indexer.
Steve Declerck wrote: public string this[int index]
What is the meaning of "this" ?
this is a keyword used to refer to the home object, i.e., the object on which the code is operating.
I don't mean to be condescending, but a good book will explain all of this in greater detail. I'd recommend Andrew Troelsen.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
Hello Vikram,
Thank you very much for your fast reply ! I understand it now...
Thanks, Steve
|
|
|
|
|
Yeah, what Vikram said.
Plus, the actual data needn't be stored in an array.
An indexer could be implemented with a database query.
The data needn't be stored anywhere at all; one could write a factorial method as an indexer:
private ulong
this
[
ulong i
]
{
get
{
for ( ulong j = i - 1 ; j > 1 ; j-- )
{
i *= j ;
}
return ( i ) ;
}
}
(Though that's fairly silly.)
|
|
|
|
|
hi all
i instaled in My PC Visual Studio 2005 and I Wount to use the WorkFlow Project , what it's need to enable the template workflow in Visual Studio 2005 .
if it need FramewWOrk 3.5 i instaled it but it is not enable .
what i can do to enable it .
thanks for all
Thaer
|
|
|
|
|
|
Thanks Mr John Adams
i instaled it . and it's Ok But the Desinger is Error
the Error Is :-
The designer could not be show for this file becouse none of the classes within it can be
designed .
what i can dot for this problem ?
Thanks Mr
Thaer
|
|
|
|
|
For VS 2005, After Installing Framework 3.0 you have to install WWF Extention .
Best Regards
-----------------
Abhijit Jana
"Success is Journey it's not a destination"
|
|
|
|
|
|
Thanks Mr Abhijit Jana
i instaled it . and it's Ok But the Desinger is Error
the Error Is :-
The designer could not be show for this file becouse none of the classes within it can be
designed .
what i can dot for this problem ?
Thanks Mr
Thaer
|
|
|
|
|
Hi,
I'm playing around with picture boxes at the moment, and was wondering...
Is there a way to stop a PictureBox from redrawing itself, so that I can draw a shape over the top of it using the form's onPaint event?
Cheers,
|
|
|
|
|
Once you start to handle the paint event, you've moved past the picture box, which is here to help people add plain images easily
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Override OnPaint handler:
protected pverride void OnPaint(System.Windows.Forms.PaintEventArgs pe)<br />
{<br />
base.OnPaint(pe);<br />
<br />
...<br />
}
|
|
|
|