|
I have a DataGridView control on a form which is bound to a class that is derived from CollectionBase and implements IBindingList. This works okay except that the sorting acts really strangely in certain situations. To sort my class I implement IBindingList.ApplySort and in the method I use CollectionBase.InnerList.Sort and pass it an instance of a class that implements IComparer to sort the data objects in my list. The implementation of the IComparer.Compare method is relatively straightforward:
object a = MyType.GetProperty(PropertyName).GetValue(x, null);
object b = MyType.GetProperty(PropertyName).GetValue(y, null);
if (a != null && b == null)
return 1;
if (a == null && b != null)
return -1;
if (a == null && b == null)
return 0;
return ((IComparable)a).CompareTo(b);
Now this sort of works okay. For example, if my data object has properties a, b, and c which are displayed on the DataGridView like this:
a b c
100 1 1
90 2 1
80 3 1
70 4 1
60 5 1
50 6 1
40 7 1
And I click on the header for row a I get this:
a b c
40 7 1
50 6 1
60 5 1
70 4 1
90 3 1
90 2 1
100 1 1
And if I click it again I get back to the original. So far so good. If I click on column b, I get the expected behavor too. However, if I click on column c (where all the values are the same) I get this:
a b c
60 5 1
50 6 1
40 7 1
70 4 1
100 1 1
90 2 1
80 3 1
Clicking a second time gets me to the second table above. Clicking a third times gives me this:
a b c
80 3 1
90 2 1
100 1 1
70 4 1
40 7 1
50 6 1
60 5 1
And finally, clicking a fourth time gets be back to the original order.
Does anybody have any idea what is going on here and how I can avoid it? This doesn't seem to ever happen if I use a DataTable as a data source.
|
|
|
|
|
I am curious as to what the code is to put an application in the Task Bar like Windows Media does when you minimize it.
The only other application I've seen do this was Norton Antivirus 2006.
I did my googles to try and find out the api calls for this but came up empty.
Anyone have a clue as to how this is done?
Steve Welborn
|
|
|
|
|
|
Excellent, just what I was looking for.
Thank you very much.
Steve Welborn
|
|
|
|
|
It appears that a ToolstripLabel control (in a ToolStrip ) won't render its text unless the control is wide enough to completely display it. This occurs even if the text contains embedded spaces.
Is there any way to relax this restriction?
Thanks,
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Hello! is there a way that i can get the serial key or other license information of a software and display it in a form.
example (Microsoft Office)
im doing this for my project about licences..
i need to compare the license in a single pc if it is registered from my server. thanks!
Paul19
|
|
|
|
|
Hi every body cloud u tell me how to register ActiveX contorl for flash exacly
"shockwave flash object" the control give me this error "Field to import the ActiveX control.Please ensure it is property registred".How to solve this problem???
Thank's
bye.
|
|
|
|
|
|
All the strings are the results of the HTTP "get" method used in a web form. See the W3C recommendations on form submissions:
http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13[^]
Basically you'd need to extract everything after the ?, then break the string up using the & as a delimiter and finally you end up with a set of properties and their values seperated by = signs.
So your first example should be read as
hl=en
q=microsoft+apple
meta=
obviously the q part is the actual query which was for "microsoft AND apple"
hasanali00 wrote: The only problem I see is what happens if google decide to change their search URL.
You'd have to rewrite your app to deal with it.
|
|
|
|
|
It is easy to add a messageFilter to an application, such as Application.AddMessageFilter. But if i use Java to call this COM component, is it possible to bond an IMessageFilter to a COM component?
Thanks
Jerry
|
|
|
|
|
Hi guys (and girls :p)
I want to combine Windows Media Player and Quicktime to be avalible in one Form.
But how do I do this?
Is there any article (on CP) which explain that?
Grtz
|
|
|
|
|
I have a strange problem. Here is what I try to achieve:
Have a background thread performing work, and sending events so the form can update controls as work progresses. To do this, i use Delegate.BeginInvoke and its companion Delegate.EndInvoke .
This works very well, except when I added another event (still works for other events, though). This event is special as the it inform the Form that an exception has occured. This event has information to display to the user as how to fix the problem.
The EventArgs has a member similar to CancelEventArgs , to tell the event raiser whether the execution of the task should be retried or cancelled. To achieve this, the event handler displays a dialog box asking the user to fix the problem. This form has buttons to ask the user if the problem is fixed or not, thus indicating the worker thread to retry or not.
I have tried to display the secondary for to the user using 2 ways (none worked):
1- Calling Form.ShowDialog directly from the event handler.
2- Calling Form.Invoke from the event handler to have the secondary form instantiated on the same thread as the form one.
None work, the code stops at the Showdialog call, the form never appears, and the worker thread finishes at the event raising line (Delegate.EndInvoke is called).
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
I tried something similar using an empty form, and it works fine. Are you sure your secondary isn't coming up behind your other windows?
I recommend you investigate the problem by simplifying it. Create a small app and focus on duplicating just the parts that you think are not working as expected.
Regards,
Alvaro
... now you see that evil will always triumph, because good is dumb. - Dark Helmet
|
|
|
|
|
Sounds like the call to ShowDialog is on the wrong thread. Have you checked that with InvokeRequired?
As a side note, I highly recommend System.ComponentModel.BackgroundWorker for what you're doing. It handles exceptions for you, passing the exception as an object to an event raised on the UI thread. No manual Invoke/BeginInvoke required.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
Unfortunately, I must use .NET 1.1. I will try the InvokeRequired.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
|
tx, interesting. Btw, the problem is fixed, I did set the Form.Enabled to false (typo in code, was supposed to be for anothe control).
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
Form.Enabled was set to false. A mistake made selecting wrong item in Intellisense
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
I have an array (List<t>) containing tens of thousands of items. I need to maintain copies of the array, sorted in a few different ways. I'm working on Windows Mobile so memory is a constraint. To minimize memory requirements, in C++, I can have arrays of pointers to the first array (T*[]). I understand I can do this in C# as well, but the code is unsafe. Is there a better way of doing this in C#
|
|
|
|
|
This should work also, because objects variables are in fact references to instances of classes, not the instances themselves, thus all arrays have the same instance reference:
object o1 = new Object();
object[] oa1 = new object[] { o1 };
object[] oa2 = new object[] { o1 };
both arrays have reference to the exact same object.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
Thanks for your reply, Michel. Does it work the same way with the generic List as well?
|
|
|
|
|
It works for all class types. struct types are passed by value, as well as primitive types
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
Thanks, just tested it and it works like you said.
<br />
namespace ListRef<br />
{<br />
class Person<br />
{<br />
public string name;<br />
public int id;<br />
<br />
public Person(string name, int id)<br />
{<br />
this.name = name;<br />
this.id = id;<br />
}<br />
}<br />
<br />
class Program<br />
{<br />
static void Print(List<Person> l, string s)<br />
{<br />
int i=0;<br />
System.Console.WriteLine("\n --- {0}: --- ", s);<br />
foreach(Person p in l)<br />
{<br />
System.Console.WriteLine("{0} {1} {2}", i, p.id, p.name);<br />
i++;<br />
}<br />
}<br />
<br />
static void Main(string[] args)<br />
{<br />
List<Person> a = new List<Person>();<br />
a.Add( new Person("jon", 1) );<br />
a.Add( new Person("mary", 2) );<br />
a.Add( new Person("hill", 3) );<br />
<br />
List<Person> b = new List<Person>(a);<br />
List<Person> c = new List<Person>();<br />
<br />
Person[] x = new Person[] { new Person("abe", 5), new Person("jim", 6) };<br />
<br />
a.AddRange(x);<br />
<br />
c.AddRange(a);<br />
<br />
Print(a, "a");<br />
Print(b, "b");<br />
Print(c, "c");<br />
<br />
c[4].id = 555;<br />
<br />
Print(a, "a");<br />
Print(b, "b");<br />
Print(c, "c");<br />
}<br />
}<br />
}<br />
|
|
|
|
|
Hi all,
I have an outlook addin which creates a Menubar in the Outlook explorer.There are 2 buttons in the explorer, when i click the buttons ,windows forms open. I have not faced any problem till this stage.But my problem arises when i try to move the form, i get distorted images of the form.Is there any way to avoid this.I have also tried making the outlook as parent form with the various APIs like SetWindowPos,ShowWindow etc.Your help is highly appreciated.
Thx in advance
|
|
|
|
|
Hi
I'm currently working on quite a big project and the need for a new custom control has come to our attention. What i´m looking for is a control that should be a combination of a textbox and a dropdownlist in the sense that i want to give the users the possibility to either select an item from the list or enter one themselves.
Is there such a control or does anyone have any ideas on how to make one..not new to custom controls just not keane on waisting time starting from scratch if someone allready knows of a good way..
Any ideas are helpful
Thanks
Henrik
|
|
|
|