ObjectSharp Consulting

Dan's Blog
Junior's Thoughts on all Things .NET

Infragistics Tips and Tricks - Part 1 of N

The current project I'm on is using Infragistics controls exclusively.  Infragistics can do some wonderful things, but damn, sometimes it does it horribly.  So here are a couple little hints and tips that might save someone a couple of frustrating moments of despair.  Find something in my list that I did wrong?  Found something I could have done better / cleaner / quicker? Please let me know.

Binding to a List<>

If you are binding your Grid to a BindingSource that in turn is bound to a Generic List, the key of your band needs to be the name of the class your list contains.

List<Message> myList = new List<Message>();
myBindingSource.DataSource = myList;
myUltraGrid.DataSource = myBindingSource;
 

Band key in your schema is 'Message'.  If your class contains another collection there will be bands for those collections which will add 'plus' signs beside all your rows even if that collection is empty.  Create another band in your schema with a key equal to your child collection and then set Hidden = true.  (See below about the Hidden property...)

The other note for binding to a generic list is that if it isn't an ObservableCollection or BindingList  (or anything that doesn't implement IBindingList or IBindingListVIew) then you are not going to get an update when you add or remove and item from the list.  If you know these things are happening you can call myBindingsource.ResetBindings(false) when they happen to update your grid with the new bindings.

Good article on what interfaces have what binding functionality.

Can't Find the .Visible property?

This one baffles me, and I'd love to know why some infragistics controls do not have a .Visible property, instead they have a .Hidden.  Watch out for that.  Apparently this is some sort of VB throw back blah blah blah.

CreationFilter's To Change GroupBy Headers

CreationFilters are a really cool concept that let you change the layout of a lot of Infragistic controls and add new functionality.  I used this to add some status lights to the GroupByRows of my grid. 

Create a Creation Filter class that implements IUIElementCreationFilter.  My AfterCreateChildElements(UIElement parent) does nothing but here is my  BeforeCreateChildElements method.  This will create 3 icons and some text in the group by row.  I create my own text element but if you want to grab the existing text element: 

DependentTextUIElement dependentTextUIElement = parent.GetDescendant(typeof(DependentTextUIElement)) as DependentTextUIElement;

 
public bool BeforeCreateChildElements(UIElement parent) { bool value = false; if (parent is GroupByRowDescriptionUIElement) { int X = 17; int Y = parent.Rect.Y + 1; int Width = 516; int Height = 17; UltraGridGroupByRow groupByRow = (UltraGridGroupByRow)parent.GetAncestor(typeof(GroupByRowUIElement)).GetContext(typeof(UltraGridGroupByRow)); DeviceStatusInfo deviceInfo = groupByRow.Tag as DeviceStatusInfo; if (deviceInfo == null) { deviceInfo = new DeviceStatusInfo("", DeviceState.Offline, DeviceOnlineState.NotOnline, "", FoundationHelper.GetImage(typeof(string))); groupByRow.Tag = deviceInfo; } string text = deviceInfo.DeviceName; if (!string.IsNullOrEmpty(deviceInfo.DeviceCurrentOperationsText)) text += " - " + deviceInfo.DeviceCurrentOperationsText; TextUIElement textElement; ImageUIElement firstIndicator; ImageUIElement secondIndicator; ImageUIElement deviceIcon; parent.ChildElements.Clear(); deviceIcon = new ImageUIElement(parent, deviceInfo.DeviceImage); textElement = new TextUIElement(parent, text); firstIndicator = new ImageUIElement(parent, deviceInfo.DeviceStatusImage); secondIndicator = new ImageUIElement(parent, deviceInfo.DeviceOnlineImage); deviceIcon.Rect = new Rectangle(X, Y - 1, deviceInfo.DeviceImage.Width, deviceInfo.DeviceImage.Height); firstIndicator.Rect = new Rectangle(deviceIcon.Rect.X + deviceIcon.Rect.Width + 2, Y, deviceInfo.DeviceStatusImage.Width, deviceInfo.DeviceStatusImage.Height); secondIndicator.Rect = new Rectangle(firstIndicator.Rect.X + firstIndicator.Rect.Width + 2, Y, deviceInfo.DeviceOnlineImage.Width, deviceInfo.DeviceOnlineImage.Height); textElement.Rect = new Rectangle(secondIndicator.Rect.X + secondIndicator.Rect.Width + 2, Y, Width, Height); parent.ChildElements.Add(deviceIcon); parent.ChildElements.Add(textElement); parent.ChildElements.Add(firstIndicator); if (deviceInfo.DeviceStatus == DeviceState.Online) { parent.ChildElements.Add(secondIndicator); } firstIndicator.ToolTipItem = deviceInfo.GetDeviceStatusToolTip(); secondIndicator.ToolTipItem = deviceInfo.GetDeviceOnlineStatusToolTip(); value = true; } return value; }

 

Set the creation filter:

this.ultraGrid.CreationFilter = new GroupRowIndicatorsCreationFilter();

 

TabClosing Event Order

This tip is kind of specific, but thought I'd post it here anyway.  If you are using the Mdi Tabbed Workspace (and I assume the Mdi Tab Control) then a little gotcha is that when the user closes a form, either by clicking the 'X' or by you firing the form.Close() method the Mdi_Tab_Closing method is fired BEFORE the Form_Closing event.  If you think about it, it makes sense, however it is a pain in the butt if you want to handle someone closing a tab, and someone closing the whole app differently.  In our app we have functionality similar to visual studio, if you caused it to fire?!? Short answer is you can't.  So here is a little method that will fire before either Mdi_Tab_Closing and Form_Closing.

protected override void DefWndProc(ref System.Windows.Forms.Message m) { if (m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_CLOSE) { applicationClosing = true; } base.DefWndProc(ref m); }

The applicationClosing bool allows me to check if the user hit the X button when I'm in my Mdi_Tab_Closing.  If you have an 'Exit' option from a file menu then in that code you will want to set applicationClosing = true in there as well.

Reset permissions for existing folders on a new Vista Install

I just did a fresh install of Vista Ultimate on my home desktop PC.  The install all went fairly smooth except for 2 things:

1) IIS was not installed, and I missed the little checkbox to install ASP support.

2) I had a lot of problems accessing my existing Documents And Settings folders and could not access (only read access) my other partitions.  Even as Administrator I could not seem to set permissions on these folders and drives so I could write to them.  Thankfully Tim Sneath came to the rescue with a posting about 'Deleting the Undeletable' in which he explains how to reset the permissions on files to give yourself access to them. 

it's not unusual to find some folders that can't be accessed, even by an administrator, because their ACLs were set for accounts with SIDs that applied to an old partition

Tim provides a quick batch command that will allow you to reset the proper permissions for the Administrators group. 

takeown /f %1 /r /d y
icacls %1 /grant administrators:F /t

Just pass it a directory to start at (it is recursive).

Big thanks to Tim.

IIS 7, ASP, and Vista

When I did a fresh install of Vista on my home desktop machine it did not install IIS by default which is to be expected.  But the real problems started when I could not find out how to install ASP support.  Anytime I would try and load an aspx file it would say it didn't know how to handle .aspx as a static file.  Very frustrating.

Barry Gervin provided a link that shows the step by step instructions on how to properly install IIS 7 on vista, including the slightly hidden ASP.NET support.  Is anyone really installing IIS7 and not installing ASP.NET support?

Vista DreamScene

While I was out at the Vista Ice House in Toronto last week they were demo'ing 'DreamScene', which is movies as desktop wallpapers.  The basic idea is that you take a small subtle looping video and apply it as your background.  Obviously this is eye candy only, but it is pretty impressive eye candy when done properly.  There is a video here that shows a couple of examples.

 

DreamScene is one of those annoying Ultimate Extras which must really drive anyone without Ultimate absolutely nuts.  Thankfully I have Ultimate, and managed to get my hands on a beta (the official release is apparently some vague time in the future), only problem is that the beta does not seem to support dual-monitors, something that hopefully will be addressed in time for the final release.  WinCustomize has started a page where you can get some DreamScene movies, apparently both in-house created, and user submitted.  It doesn't appear that the page is ready for primetime, but you can check it out none the less.

How Smart Are You?

How smart are you? http://crux.baker.edu/cdavis09/roses.html A very challenging little game, some people can do it in 5 minutes, apparently others take a year... took me about 20 minutes.

Is Google Taking Over My Computer?

It has been rumoured for months, but finally today it was announced that google had entered the Desktop Search business with Google Desktop. Anyone that has ever used Microsoft Windows Search knows it is a big pain, and it is slow and the indexing is pretty bad. Needless to say I've been looking forward to the newest addition to the Google family, and I downloaded it as soon as I heard.
Right off the bat I had a bit of a problem with the install not working because I had Microsoft Firewall Client Version 3 installed, instead of version 4. Even though this is disabled it would not let me continue the install.
Once I was past that problem, it was fine and I started playing with it. It is amazing. Amazing.

It does a one time indexing of your system when there is some idle time, and after that it just keeps track of new and changed files as you work. The searches are amazingly quick and search text files, Word docs, Excel spreadsheets, Outlook mail, browser cache, and all your file names. To do a search for 'jpg' took 0.04seconds and it returned every picture on my computer and every email in which I ever sent, or mentioned a jpg file in. Amazing. Why have you not downloaded it yet?

There is one beef that I have. I've considered this problem and I've decided it might be a premeditated decision, but I hope it is not. Google Desktop does not look at .cs files, as a C# developer this is very frustrating. For the VB.NET guys it doesn't do .vb files either... Google Desktop will treat .java .c .h .cpp files as text files AND allow for a "filetype:c" or "filetype:java" search. But nothing on .cs files. Google what is the deal with this? I also haven't been able to find anyway to change how certain file types are handled.

Despite this problem I still love it, it integrates itself with http://www.google.com so that any search on the site will also tell you if you have matches on your own machine, this is done by intercepting google requests and then merging your results with the html when your response comes back. None of your personal info is sent to Google, rest easy. The only thing that is sent is how many searches are run, and how long they took, and even this you can opt out of.

Google is the greatest thing in the world, Dave will tell you how much he loves Google if you ask him.
As well as taking over the internet, it is also taking over my machine, I now have my Gmail, and the Gmail Notifier, Picasa for all my pictures, Google Desktop, and Google Deskbar. I don't mind this take over a bit.

Clipboard Copying Problem

I recently ran into a problem with the clipboard that is apparently a fairly common problem without a common answer.
The problem occurs while making a temporary copy of the clipboard.

I needed to put something into the clipboard, but I didn't want the user to lose what they already had in there, the easy way that I assumed would work looked like this:

IDataObject oldClipboard = Clipboard.GetDataObject();

//random clipboard manipulation here

Clipboard.SetDataObject(oldClipboard,true);


The true ensures that the data is held in the clipboard even after the program closes.  This solution meets with a "The requested clipboard operation failed" message if there is ever anything actually in the clipboard originally.

 

So here is the proper way of making a copy of the clipboard data, assuming of course that you have no idea what is in the clipboard before you arrived.  An important note if you aren't aware of how the clipboard is structured.  When you copy text out a richtextbox it is actually stored in several different ways:
Rich Text Format
Rich Text Format Without Objects
RTF As Text
System.String
UnicodeText
Text

 

The solution:

IDataObject oldClipboard = Clipboard.GetDataObject();

DataObject newClipboard = new DataObject();

string[] s;

s = oldClipboard.GetFormats(); //gets all the possible formats for that data

foreach(string ns in s)

{

newClipboard.SetData(ns,oldClipboard.GetData(ns)); //re-associate the old data with the proper types

}

//this is where your clipboard manipulation goes.

Clipboard.SetDataObject(newClipboard,true); //true makes sure the data persists

 

 

Web MSN plus SP2 and BitTorrent

Well MSN has knocked one of its shortfalls of the list (it's pretty long).

I heard last week that Microsoft had openned up a web-based version of its popular MSN client, but everytime I tried it the site seemed to be down. However it seems to be up and pretty stable, and it's pretty nice too. Microsoft seems to be doing some pretty great things with WebGUI's, WebOutlook looks almost identical to normal Outlook, and now web MSN looks amazingly like MSN as well.

So everyone give it a try at http://webmessenger.msn.com/

 

Also a note on SP2, anyone installed it yet? I heard a lot of bad things during the beta stages, I assume that Microsoft fixed all these problems before they turned it Gold, but I'm still a little hesitant. IBM has apparently asked its users to hold off with the install. Apparently this is routine, but I now have a mounting list of 'apparents and hopes'. The list of improvements does sound nice though, maybe not for myself (but the new WiFi improvements should be interesting to see) but more for the family that I have become the unofficial tech-support for. There is a good article at NeoWin about the improvements and beefed up security.

 

My last note is that at http://sp2torrent.com/index.php you can get a Torrent for the new SP2 (which is a pretty big file). I'm glad to see that there are people trying to show a legal use for P2P before the US Government ups and makes it illegal. My car has illegal uses too, but I haven't heard of any bills before the US Congress to ban cars for any use...

Canada Lost The Stanley Cup?

More than a few of my American friends have used Tampa Bay's win in the Stanley Cup finals as an attempt to bash on Canadian hockey. 'Canada hasn't won a cup in more than a decade'.
Haven't they?
Yes geographically the cup has not been won by a team north of the border. But where do you think the cup spends most of its time in the off-season? Canada. Each players gets a day (or week, some amount of time) to bring the cup to their home town. Which means that the cup will spend 2 days south of the border this summer.
Thats right, Tampa Bay has 19 Canadians and only 2 Americans.
Ben Clymer (5 Games, 0 points, 2 shots)
John Grahame (1 Game (only 34 minutes), 3.54 GAA, 0.884 Save %)

And here are some interesting numbers related to the NHL's yearly hardware giveaway. Big thanks to Gord for the numbers.

There have been 112 Stanley Cups:

111 Canadian Captains.
107 Canadian goalies.
39 Conn Smythe Winners, 37 Canadians.

Can you name the non-Canadians? One of the Conn Smythe winners is easy, the other, won back in 1994...
You can email me at daforsyth !at! objectsharp.com if you want the answers.



49 Norris Trophy Winners, 39 Canadians.
Lidstrom 3 times, Chelios 3 times, Leetch twice, Rod Langway twice (actually born in Taiwan).

76 Vezina Winners, 65 Canadians.
Before 1982 this was essentially the Jennings and I believe that the 100+ Goalies that received the Vezina prior to 1982 are all Canadian. I could be wrong on a couple though.
Also of note is that of the 11 non-Canadians winners, 6 of them are Hasek.

30 Jack Adams, 30 Canadians. This year might be a first, but my vote is with Sutter.

33 Lester B. Pearson Awards (NHLPA voted MVP), 27 Canadians. Jagr twice, Hasek twice, Naslund, Federov. Hull may be a legal american, but he was born and bred on Canadian hockey so I don't count him as an exception.

80 Years of Hart Trophies. 73 Canadians. Hasek twice, Jagr, Forsberg, Federov, Mikita twice. Once again I count Hull as a Canadian.

86 Scoring Leaders/Art Ross, 76 Canadians. Jagr 5 times, Mikita 4 times, Forsberg once. For this I'm hazy on the pre-1960 winners, but I'm fairly certain they were all Canadian.

So there are the numbers, also of note though is that most news outlets are reporting that Calgary had up to 5000 more people at their 'we lost' party than Tampa Bay had for their 'we won' party...

Don't get me wrong, I would have loved Calgary to win the Cup, but by the same token lets not pretend this is an Olympic Gold Medal won by a team of all Americans..... back in 1980.....


Thanks to Dave for the flag.

Monad, it isn't just danom backwards anymore.

I'll be the first to admit that I haven't been paying a whole lot of attention to Longhorn. I went to the token meeting, I listen to Barry and Dave, but that's about as far as my indoctrination goes. However, maybe today that changes. I started to read a couple articles on the Monad Shell (MSH).

The Monad Shell is Microsoft's kick at the powerful shell engines you find in the *nix systems. As a recent graduate from the academic world which is ruled by the *nix systems, I've always held that a decent shell engine is what Windows lacked the most (I've also added a decent file search engine now).

MSH introduces the new concept of a Commandlet (Cmdlet), these cmdlet's are the new .exe, .bat, or .com with a twist. The cmdlets are in fact .NET libraries, more closely related to a DLL than an EXE.

With the help of reflection and metadata inside the class, MSH will validate and map command line parameters to the properties of your class/cmdlet. Metadata is also the mechanism that MSH uses to identify a normal class library from a cmdlet.

So far this all sounds somewhat interesting, and maybe useful, but the best is yet to come.
Piping. Microsoft has done something great here, they have taken the already great idea of piping and improved it 100%. Gone are the days of piping text, here are the days of piping objects. Here is one of the examples from the WinHEC presentation. get-process | where “handlecount –gt 400” | sort handlecount | out-chart processname,handlecount I think its pretty self-evident what is happening here except perhaps the last piping command. out-chart will apparently output the results into an excel chart using the associated values of processname and handlecount. All of these commands now return an output stream that contains and object, not just a flat string representation of what SHOULD have be an object. The cmdlets have access to more than just the single output stream as well, by default they have the output stream, and an error stream. Also available are verbose, debug, and progress streams.

Seamless Navigation. I haven't tried this myself, but it would be nice if it turns out to be true. Microsoft claims that the new shell will enable seamless navigation between the: File system, Registry, AD, and WMI. Lets hope that's the case.

Now, I just need to find a place to install longhorn so I can try all this great stuff out.

The slides from WinHEC can be found here.

Anyone played with this yet? Let me know what you think/thought.

VS.NET Inherited Forms Bug

VS.NET Bug. I was asked to look into a problem last week involving some moving buttons in the designer. The problem was occurring in inherited forms where the parent form contained some protected, and anchored controls. When you resized the child form in the designer and build, Vs.Net would create some interesting locations and sizes, often time off the form entirely. These location and size values are set in the InitializeComponent() which makes things difficult.

So, after some searching and digging I found an interesting KB article, that explains its a bug.
However Microsoft's solutions are actually the causes in VS.NET 2003.
Basically there are a few options:
  • Once you have the controls have been moved, delete the offending locations and sizes from the InitializeComponent() and they will inherit their values from the parent again.
  • Create another size and location property and replace the erroneous values with these hard coded values after InitializeComponent().
  • Change the protection level to Friend.


    Obviously some of these solutions have their own problems, but the bug is fixed in the latest beta release of Whidbey so just bide your time for a bit.
  • Search

    Syndication