|
ive overrided the drawItem method in my control [derived from ListBox] and wen i insert it into the designer, it moans about the OnDrawItem method, and i just wondered if there was anything special i was supposed to put in it
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
I asked about one or two weeks ago about how could I get the value of an autonumber filed in the record I had just inserted in one step. Several proposed using @@IDENTITY in a second step.
There's a way to do it in one step:
http://www.4guysfromrolla.com/webtech/tips/t122600-1.shtml[^]
I did it like this in C#:
string sSQL = "INSERT INTO Customers (FirstName, LastName) VALUES (' ', ' '); SELECT @@IDENTITY;";
OleDbCommand oCmd = new OleDbCommand(sSQL, oConn);
oCmd = new OleDbCommand(sSQL, oConn);
nCustomerID = Convert.ToInt32(oCmd.ExecuteScalar().ToString());
Hope it helps someone else!
-- LuisR
──────────────
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
"Do not worry about your difficulties in mathematics, I assure you that mine are greater." -- Albert Einstein
|
|
|
|
|
Hi all,
How does one assign a property or a member or a string to be the value that is shown in the auto's and local windows? I thought this was ToString() but that doesnt seem to work. I also cant seem to find an Attribute doing this...
I'm particularly interested in "naming" delegated methods. Dont know if this is the same as above?
Any suggestions?
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
Thx David, but that is not it, all they discuss there in in VB terms what an indexer in C# is.
If you look at a control for example, its Text property is shown instead of the class name, which is default.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Perhaps it uses the DefaultProperty attribute? I'm not seeing anything where it says what it uses so I'm just as lost as you are
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
I found this in the Control classes MSIL:
.custom instance void [System]System.ComponentModel.DefaultPropertyAttribute::.ctor(string) = ( 01 00 04 54 65 78 74 00 00 )
So there is a DefaultProperty attribute in the System.ComponentModel namespace. I bet that's what needs to be implemented.
David Stone
It seemed similar to someone saying, "Would you like to meet my knife collection?"
Ryan Johnston on Elaine's sig
|
|
|
|
|
I'm having a problem with a simple String "Replace"
I am passing in a GUID into the function (see code below).
The GUID includes "{-}" characters. The function below should strip those chars,
but it is returning the original string.
Any suggestions? tia.
private string StripPunctuation(string sourceString )
{
int counter;
string PunctuationCharacters;
string buffer = sourceString;
int StringLength;
PunctuationCharacters = "`!@$%^*()+=\\|[]{};:<>/?,~";
StringLength = PunctuationCharacters.Length;
buffer.Trim();
try
{
for (counter = 1 ; counter < StringLength ; counter++)
{
buffer.Replace( PunctuationCharacters.Substring(counter, 1), "");
}
buffer.Replace((char) 34, (char) 0);
return buffer;
}
catch
{
return sourceString;
}
}
Mike Stanbrook
mstanbrook@yahoo.com
|
|
|
|
|
strings in .NET are immutable; so when you call Replace on a string object it doesn't modify it; instead it returns a new string object containing the modified text.
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
Hmm.. I guess I skipped that chapter...
So an alternative would be:
buffer = buffer.Replace("x","y");
thanks.
Mike Stanbrook
mstanbrook@yahoo.com
|
|
|
|
|
A much better alternative would be to use Regular Expressions; that's what they're made for.
The regex to match everything in a string except for {, -, and } is: "[^-{}]" . So, in a one-liner:
buffer = System.Text.RegularExpressions.Regex.Match(buffer, "[^-{}]");
Much better, no?
-Domenic Denicola- [CPUA 0x1337]
MadHamster Creations
"I was born human. But this was an accident of fate - a condition merely of time and place. I believe it's something we have the power to change..."
|
|
|
|
|
Oh yes! Much better!
Not that it is critical, but any idea how the RegExp functions match up with String.Replace in terms of performance?
Thanks for the nudge in the right direction!
Mike Stanbrook
mstanbrook@yahoo.com
|
|
|
|
|
MStanbrook wrote:
Not that it is critical, but any idea how the RegExp functions match up with String.Replace in terms of performance?
Not really... generally for simple operations string.Replace is faster, at least in PHP. I dunno about in C# though. If all you wanted was {, }, and -, then the fastest code would probably be:
buffer = buffer.Replace("{", "").Replace("}", "").Replace("-", "");
For more advanced RegExs, they're probably faster than multiple string operations.
I'm not sure about any of this though; a bit of benchmarking wouldn't hurt (run both a hundred times and print the number of milliseconds). I'd be interested in the results if you do something like that.
-Domenic Denicola- [CPUA 0x1337]
MadHamster Creations
"I was born human. But this was an accident of fate - a condition merely of time and place. I believe it's something we have the power to change..."
|
|
|
|
|
How would I go about the following?
I have 3 objects named A, B and C.
I want an array(list) of object[] of all combinations that object[]{A,B,C} can be. IOW, the order is of importance.
I want visually something like this:
ABC
BCA
CAB
BAC
CBA
ACB
as a result. Is there any of you math guru's around? I'm pretty sure this is elementary stuff, but my ol' rusty brain.....
I do remember # combinations = n x (n-1) x (n - 2) x ... x (n - n), cant remember the name of it either
UPDATE: oops that must be x's not +'s
Cheers
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
|
|
Thx Richard, it seems sometimes it doesnt pay to wait for the news letter.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
C(p,n)=p!(n-p)! is Newton's binom.
n=3;
s1 = "A";
s2 = "B";
s3 = "C";
print s1,s2,s3
for (i=0;i<n-1;i++)
{
c = s1;
s1 = s2;
s2 = s3;
s3 = c;
print s1,s2,s3
}
c = s2;
s2 = s3;
s3 = c;
print s1,s2,s3
for (i=0;i<n-1;i++)
{
c = s1;
s1 = s2;
s2 = s3;
s3 = c;
print s1,s2,s3
}
And I swallow a small raisin.
|
|
|
|
|
Where do i turn right? LOL just kidding, I cant figure what you are doin, please excuse my frail C# brain
Anyways, it s seem the the Combinatrial class will do the job maybe...well it works for the one part as i described above.
I must see if the class supports "expanding" . What i mean is this:
You have 3 objects (delegates in my case) A,B,C. Now I need what I call a unique population (sounds nice hey ), meaning given an object[] of size x, it should populate it with unique lexographical combinations of A,B,C.
EG: x is 5
AAAAA
AAAAB
.....
BCCCC
CCCCC
Again order is of importance.
I read this on the article:
One last thing to mention : This library generates only combinations, variations and permutations without repetition. If you need repetition you have to implement it yourself. I do not have a need for such functionality right now, so probably won’t write it very soon.
Is this what is meant by it?
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
I derived that the number of possible "repeatable combinations" (proper words ) would be:
# = n ^ size where n is the # of unique objects and size is the width of the "population".
EG: (using 0 and 1 for clarity)
Repeatble Combination of 0 and 1 with size 2: 2 ^ 2 = 4 combinations
0 0
0 1
1 0
1 1
Repeatble Combination of 0 and 1 with size 3: 2 ^ 3 = 8 combinations
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Now this leads me to believe i could effectively "count" the combinations by applying a unique tag for each object using the numbers of objects as base number. In this case, 0 and 1, counting in binary (base 2).
Now if we have say 3 objects, A B C, we tag 0 1 2, base 3. At this point I must say, this is all my own theorizing and I could have it all wrong. Now, if I am right, all I need to use is non standard base numbers for counting.
Is there an easy way to do this? Maybe a formula? Does .Net have builtin support for nonstandard basenumbers like this?
All help appreciated
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Want the sarcastic answer ? You're wrong
The binary combinations you showed here can be described as : all combinations of 2 elements (0 and 1) in 2 slots. That's indeed 2^2 = 4.
If there are 3 slots, that's 2^3 = 8.
But wait, that's not the right rule !
Your problem described yesterday was : all the combinations of 3 DISTINCT elements in 3 slots. Which is C(p=2,n=3) = 6. This can be obtained programmatically by doing shiftings and swappings, as I showed you. It is likely that the codeproject article pointed by someone else about combinations ad stuff like that will output these exact kind of coimbinations.
In fact you should ask this guy to show you how his API could be used to solve your problem, if you'd like a general purpose combinational answer,
And I swallow a small raisin.
|
|
|
|
|
Thanx, but I was referring to the second part of my problem , getting all the "repeatable combinations" which the articles class do not provide.
http://www.codeproject.com/script/comments/forums.asp?forumid=1649&select=266431&df=1&app=50#xx266431xx
Look there
I'm currently try to make a class to handle this
BTW: I couldnt understand that explaination of your (no offense ) and found one that makes a bit more sense to me
class Perm
{
public void swap (ref int a, ref int b)
{
int temp = a;
a = b;
b = temp;
}
public void perm (int []list, int k)
{
int m = list.Length - 1;
int i;
if (k == m)
{
for (i = 0; i <= m; i++) Console.Write (list [i]);
Console.WriteLine (" ");
}
else
for (i = k; i <= m; i++)
{
swap (ref list [k], ref list [i]);
perm (list, k+1);
swap (ref list [k], ref list [i]);
}
}
}
Looks like it works on the same principal
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
class Answer
{
Answer();
Dispose()
{
}
}
And I swallow a small raisin.
|
|
|
|
|
NotCorrectAnswerException("It does not support any amount of elements") thrown
But no worries, I think I have done it
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|