|
Hi,
you need a CompareTo method that compares the first sorting property first;
if the result is zero (which means the first property is indecisive), compare the second,
etc. until you have a decision on the relative sort order.
So it could look like this:
int diff=People1.Firstname-People2.Firstname;
if (diff==0) diff=People1.Surname-People2.Surname;
if (diff==0) diff=....;
return diff;
[CORRECTION] the - operator is not appropriate for string compare;
use diff=string.Compare(People1.SomeProperty, People2.SomeProperty); instead;
remark: Compare() has overloads to control case sensitivity [/CORRECTION]
-- modified at 14:39 Thursday 6th September, 2007
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thanks Luc, I can see how that may work. Getting this error message though:
Operator '-' cannot be applied to operands of type 'string' and 'string'
|
|
|
|
|
You don't want to use the '-' operator. You can compare string using String.Compare(str1, str2). This returns an integer that would give you proper sorting. You can ignore case if you want by using String.Compare(str1, str2, true).
So the code would be something like:
Int32 order = String.Compare(p1.FirstName, p2.FirstName, true);
if (0 == order)
order = String.Compare(p1.LastName, p2.LastName, true);
return order;
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
sorry, my mistake, it is OK for integer data; for strings what you can do is:
diff=String.Compare(string1, string2);
which also offers an optional "ignore-case" argument.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thanks I'd actually just figured it out.
int diff = string.Compare(this.Surname, tmpObj.Surname);
Works perfectly! I wish I'd asked about 8 hours ago when I started working on this :->
Dave
|
|
|
|
|
DaveyM69 wrote: I wish I'd asked about 8 hours ago
Well, it is OK to try and solve a problem yourself. Analyzing a problem,
trying different approaches, and searching effectively all are part
of the learning curve; of course if these don't bring the solution in a
reasonable amount of time, you should launch a question on a forum like this one.
And once you got a solution, reflect on why you did not find that by yourself and/or sooner.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi..
could someone plz help me out..
I want to create a number of classes. i was told to use nested classes. but im a bit unclear as to how to do this.
Looking at my tables in my database, i have the followin tables: User(list of pc users), Logon(has date,user and pc), File(the file on that PC), PC, Group(the group to which that pc belongs). With these tables i want to generate reports.
Ive started creating the class for User but now how do i go about creating the rest?
|
|
|
|
|
rcwoods wrote: I want to create a number of classes. i was told to use nested classes. but im a bit unclear as to how to do this.
public class OuterClass
{
public class NestedClass
{
}
}
rcwoods wrote: Looking at my tables in my database, i have the followin tables: User(list of pc users), Logon(has date,user and pc), File(the file on that PC), PC, Group(the group to which that pc belongs). With these tables i want to generate reports.
Ive started creating the class for User but now how do i go about creating the rest?
What has this got to do with nested classes?
How you created the other classes? In the same way as you created the User class I would guess.
|
|
|
|
|
rcwoods wrote: I want to create a number of classes
Maybe you mean linked classes? So as to follow the Relationships that exist (supposedly) between the database tables.
If so then you probably want something like:
<br />
public class User<br />
{<br />
}<br />
<br />
public class PC<br />
{<br />
}<br />
<br />
public class Logon<br />
{<br />
private User _user;<br />
public User User<br />
{<br />
get { return _user; }<br />
set { _user = value; }<br />
}<br />
<br />
private PC _pc;<br />
public PC PC<br />
{<br />
get { return _pc; }<br />
set { _pc = value; }<br />
}<br />
<br />
Kinda like that?
-- modified at 15:38 Thursday 6th September, 2007
|
|
|
|
|
Jason Hanford-Smith wrote: Colin Angus Mackay wrote:
I want to create a number of classes
I never said that - You are misquoting me. Your response should have been addressed to the OP.
|
|
|
|
|
Wow, I've never seen such a touchy bunch.
Apologies... May I never put words in your mouth again.
|
|
|
|
|
I just think the CP regulars are starting to get a bit tired of bad subjects, posts for finished code, false quotations, students trying to take the easy road through programming lessons, multi posting, cross-posting, off-topic questions/answers and so on.
We've all been growing a bit touchy I guess.
-Larantz-
|
|
|
|
|
Yep - I'm going to try some activity that doesn't require a lot of brain power. I'm going to paint my hallway.
|
|
|
|
|
And the color of the day is - black I presume?
Happy painting!
-Larantz-
|
|
|
|
|
Dulux Daffodil white in a silk finish, actually.
|
|
|
|
|
That's me finished one wall and I've cleaned up for the evening. Tomorrow I'll try and finish the rest of the hall. (Well, at least the first coat - The previous owners had a big brown rectangle painted on the wall, I think that area might require an extra coat because I can still see it, just.)
|
|
|
|
|
At the risk of hijacking the OP's question, what sort of problem maps more appopriately to a nested "composition" design?
I just read one illustration that used a car and its engine as an example. They argued that composition, and a nested engine class, made sense, because a car cannot work without an engine. But this doesn't make much sense to me, as a car could have any number of types of engine or the engine could be removed completely (as happened to my car yesterday) and replaced.
Me: Can you see the "up" arrow?
User:Errr...ummm....no.
Me: Can you see an arrow that points upwards?
User: Oh yes, I see it now!
-Excerpt from a support call taken by me, 08/31/2007
|
|
|
|
|
Hi,
you don't need nested classes: you can create all classes at the top level of some namespace.
IF a class is to be used only inside some other class, then you CAN turn it into a nested
class, and completely hide it from the outside world. That would offer a higher degree of
encapsulation, at the risk that you sooner or later want to use the inner class independent
of the containing class...
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Ah, thanks Luc.
The more I know about C# the less I know - and there's another mystery solved.
Me: Can you see the "up" arrow?
User:Errr...ummm....no.
Me: Can you see an arrow that points upwards?
User: Oh yes, I see it now!
-Excerpt from a support call taken by me, 08/31/2007
|
|
|
|
|
Is there any way to change the position of the help panel in a PropertyGrid in code?
|
|
|
|
|
Sorry, I don't think so. If you use Reflector[^] to view the source for the PropertyGrid you can see that the private method OnLayoutInternal positions the help panel (this is called doccomment in OnLayoutInternal).
The best you can do is hide it. You may be able to request such a feature from a third-part vendor (such as SmartPropertyGrid[^]).
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
How do you hide it? I have a situation where I want a fairly simple PropertyGrid, but I do not want the help panel to display.
Thanks,
John
|
|
|
|
|
As Tom said, the MS PropertyGrid can't do it. However, Smart PropertyGrid.Net can definitely position the comments area the way you want (some of my customers wrote a piece of code so that the size is adaptable to the height of the comments).
|
|
|
|
|
Hi,
I wrote a web service which needs to return a list of string objects. I tried using string[] as my return value and couldn't get that to work. I then tried using an ArrayList and couldn't get that to work either. I read some stuff on it and in my program which uses the web service I could get my string values like this:
Object[] items = GetItems();
I then cast my items back to strings.
This is OK but how can I get the actual ArrayList back?
ArrayList items = GetItems();
Thanks 
|
|
|
|
|
Hm.
I stopped using ArrayList a while back when generic lists came.
For instance: List<string> items .
I'f my memory hasen't failed me completely, you should only have to set the method returnvalue to ArrayList, like public ArrayList GetItems(); and return your ArrayList in a normal fashion.
Have you tried using generic lists?
-Larantz-
|
|
|
|