Archive for December, 2007

DateTimePicker - no BackColor property, not nullable

More Windows forms stuff. I don’t like really complex Web forms controls ‘cos sometimes they seem a bit flakey - but I’m beginning to wonder if Windows Forms stuff is any better.

Two problems with the DateTimePicker. First, it can’t have a null value. What? You might not want to have a value in it? That’s craaazzzy! Inconceivable! What do you mean that your database tables allow null values in a DateTime column?

All you can do is set ShowCheckbox to ‘true’. This will give you a little checkbox, to turn on or off the editing of the value. You could then wrap the DateTimePicker, and return yourself null if the ‘Checked’ value is false.

Secondly, it has no BackColor property, so I couldn’t colour it pink when the field was invalid, meaning it had to have a value - therefore, the checkbox mentioned above has to be ‘Checked’. I managed to get around this by subclassing the DateTimePicker - but had some problems when you then focussed on it to try to edit it. My solution (below) was to turn off any background colour during editing…

Read more »

TableLayoutPanel - doesn’t autosize or autoscroll correctly

I’ve been doing some Windows forms programming lately - not really my thing, but needs must. I’ve got an application which needs to dynamically create a form at run time, and so I’m using a System.Windows.Forms.TableLayoutPanel.

All the controls contained by the TableLayoutPanel resize automatically, and the TableLayoutPanel automatically provides scrollbars. “Great!”, I thought, “This will deal with large forms nicely.” Wrong!

The problem is when form has too many fields - it becomes deeper than the display area of the TableLayoutPanel. This is fine - the TableLayoutPanel should automatically add a vertical scrollbar, and adjust the size of the controls it contains to fit in the smaller area. Except it doesn’t. What I actually get is this:

Problems with TableLayoutPanel

Notice that I’ve got a vertical scrollbar, but it hasn’t resized the child components. This, they overlap some of the fields - and I now have a nice horizontal scrollbar. Arse.

I eventually found that others had had this problem and told Microsoft about it. However, they’ve decided not to fix it. Thanks Microsoft, that cost me an hour and half - it’d be wise to fix it. I found the answer from the same link - add a vertical scrollbar’s width as padding on the right of the TableLayoutPanel.

The circular logic of the WSS Lists Webservice GetListContentTypes call

So, I need to get a list of the content types applied to a library. The Lists webservice has a call for this:

<getlistcontenttypes xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listname>string</listname>
<contenttypeid>string</contenttypeid>
</getlistcontenttypes>

So, I’m connected to a site, I supply a list name to identify the list… …but what do I give as a contentTypeId? I don’t have a f$%king clue - I was calling this function to try to find out what content types were valid!

Well, good news. It doesn’t seem to matter what you put in, you always get a list of all the content types on the list. I used the following code…

WS_Lists.Lists lsts = new WS_TestApp.WS_Lists.Lists();
lsts.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlNode node = lsts.GetListContentTypes(libraryName, contentTypeID);

I figured that maybe they wanted the base content type for what I wanted back, so I tried setting contentTypeID to documents (0×0101) and got back a list of all the content types. I then set contentTypeID to “fish”, and still got back a list of all the content types. As far as I can tell, the second parameter doesn’t do anything.

Side note: The first content type returned is your default content type.

Side note 2: There doesn’t seem to be an easy way of identifying non-visible content types…

Are web services really that great?

So I’ve been working for the last few days using SharePoint’s web services extensively. They are pretty neat insofar as they offer a very public set of interfaces - the communication is pretty much human readable (for a given geekiness of human).

However, a couple of things have struck me. First was the bandwidth needed. Some of the calls I’m making were getting back 50k responses - and for a simple action in the app I’m working on, I could have to make lots of those just to display a form to a user. 1Mb downloads to show this form were likely - so this isn’t great. Presumably, enabling compression on the web server should reduce this considerably (looking at the XML in the file, it seems to have a high redundancy), but only at the cost of extra processing. Still, I can live with that.

The second, and in some ways more fundamental point, is that I find myself having to write wrappers for the various web services. I know, calling a web service in C# is dead easy, and that’s great, but the response -yuck! Everything seems to come back as lots of XML. And I do mean lots. I don’t actually want to deal with reams and reams of XML. Object oriented programming sort of implies that I should be trying to deal with objects. After all, that seems to be what much of ADO.NET is about - presenting data as objects.

So, for comparitively well known web services, can’t we have a pre-built wrapper so that I’m just dealing with objects? Both in and out. That way, well, if I want to talk to the web service via XML, directly, well, I can. If I’d sooner work with objects, then I could do that also. Just at the moment, there seems to be an asymmetry - I supply an function with parameters and it produces the request in XML. Then when I get the response, well, it’s just XML.

Hell, isn’t that what SOAP is all about? A common communication layer between remote objects?

In fact, thinking about it, some of the web service requests need XML put into them too - but that’s CAML, and another gripe entirely.

I’m now a ‘Professional Developer’

MCPD Logo

Presumably, everything I’ve written over the last 7 years has been amateur (well, some of it was, certainly). This is in addition to my being…

MCTS Logo

To be honest, I still feel I’m being firehosed with information about Microsoft stuff, and that I’m struggling to keep up. But I guess that the point of such certifications is that they demonstrate a level of ‘minimum competance’ - that is, the holder still might be “Good” rather than “Brilliant”, but at least you can be fairly sure that they aren’t “Completely Inept”.

Anyway, I learnt a lot doing the Professional Developer exam - or rather, reading the course materials. The exam itself, well, I felt that some of the questions were a bit too technical, while the book seemed to cover a higher level view of the system (at least, in it’s good bits). See my comments on the book I used.

MCPD Self Paced Training Kit: Designing and Developing Web-based Applications using the .NET Framework

by Mike Snell, Bruce Johnson, Brian C. Lanham, Sara Morgan, Shawn Wildermuth

Despite the snappy title, I actually found the book generally pretty good, but some chapters were definitely better than others. A few, I felt, were very good, such as requirements gathering and use cases, modelling the application, and so on - but many of the later chapters were less useful. There seemed to be an inverse relationship between how many code examples there were, and how good a chapter was. I think that the chapters with little code assumed that if you were through to doing the MCPD exam, you can probably work the code out for yourself, or perhaps that the presence of code examples showed a move away from considering the design bit of ‘Design and Developing…’

That said, the exam didn’t really match up with my expectations, or what was covered in the book. If anything, the exam seemed to be about a lot of the stuff I’d covered previously in the MCTS exams. So neither really hit exactly what I felt I should’ve been examined on, and the book and exam didn’t really cover the same areas. And there are probably better books out there for covering development generally.