Saturday, June 11, 2005

Showing a true read-only DataGrid 

I had an interesting situation the other day where I wanted to use a WinForms DataGrid to display a read-only list of some ECO classes. I soon discovered that there is no easy way to support having a DataGrid where the entire row is selected when a record is clicked. Even though the DataGrid is read-only, an individual column can still get focus, with the caret painted and the contents highlighted.

Normally to get around this problem I would revert to using a ListView, where getting this behaviour is easy. But as the DataGrid was being used in an ECO WinForms application, I wanted to still use it so I could take advantage of the EcoFormExtender functionality offered when doing so. This includes being able to add, edit and delete ECO objects without writing a single line of code.

After a bit of judicial Googling, I found that I should be able to get the behaviour I wanted by creating a DataGridTextBoxColumn descendant and overriding its Edit method. Below is the code for this :-

procedure TDataGridUnselectableCellColumn.Edit(ASource: CurrencyManager;
ARowNumber: Integer; ABounds: Rectangle; AReadOnly: Boolean; AText: string;
ACellIsVisible: Boolean);
if (FSelectedRow > -1) and (FSelectedRow < ASource.List.Count) then
FSelectedRow := ARowNumber;

This is all well and good, but I don't have design-time support for this TDataGridUnselectableCellColumn class, and I don't really want to stuff around too much to see if it is feasible to create a DataGrid descendant just so I can get it. To get around this problem, I created a base form containing a DataGrid which calls the below method on the WinForm.Load event :-

procedure TDataGridForm.InitializeGridColumns;
lTableStyle: DataGridTableStyle;
lSourceColumn: DataGridColumnStyle;
lDestColumn: TDataGridUnselectableCellColumn;
lTableStyle := DataGridTableStyle.Create;
if dgMain.TableStyles.Count = 1 then
for lSourceColumn in dgMain.TableStyles[0].GridColumnStyles do
lDestColumn := TDataGridUnselectableCellColumn.Create;
lDestColumn.Alignment := lSourceColumn.Alignment;
lDestColumn.HeaderText := lSourceColumn.HeaderText;
lDestColumn.NullText := lSourceColumn.NullText;
lDestColumn.PropertyDescriptor := lSourceColumn.PropertyDescriptor;
lDestColumn.MappingName := lSourceColumn.MappingName;
lDestColumn.Width := lSourceColumn.Width;

So I now have an easy way to have a read-only display of a list of my ECO objects, simply by descending from this TDataGridForm and configuring the DataGrid.TableStyles property to contain the column mappings for the class attributes I wish to display. Not the most elegant solution for sure, but one I can live with for now.

(0) comments

Friday, June 03, 2005

Just when you thought the .NET Framework couldn't get any smaller 

I've been programming using the .NET Compact Framework for a little while now, and enjoying how easy it makes development on portable devices such as PocketPCs.

Well it seems that Microsoft are taking this one step further with the introduction of the TinyCLR. In a nutshell, it is a cut down version of the .NET Framework which is embedded right in the processor of devices using Smart Personal Object Technology (or SPOT). So developers can write managed applications which essentially target an embedded microcontroller. This sounds like one interesting piece of technology, and one I'll be keeping a keen eye on.

And I'd love one of those MSN Direct watches. It's a shame the're currently only for the USA/Canada market

(0) comments

Thursday, June 02, 2005

I've fallen head over heels in love 

One of the tasks which has been on my TODO list for quite a while now, was to learn how to leverage the power of Borlands Enterprise Core Objects model driven architecture framework. Well, I've finally bitten the bullet and have started implementing my first personal project using it.

This project will involve an ECO WindowsForms application to enable the user to enter data into a repository, and an ECO web service application to allow other applications to consume and add to this data. I may even throw an ECO ASP.NET application into the mix for good measure.

I've been working on this over the past week in my spare time, and all I can say is 'WOW!'. It is amazing the amount of plumbing code we all take for granted as part of a normal application, which ECO now takes care of for us. I can see this having an astonishing effect on my future application development productivity. I'll be able to concentrate more on the business problem at hand, rather than common implementation details such as retrieving my business objects from my persistence layer.

One of the biggest complaints that ECO seems to get is its lack of documentation. It is a complex framework, with many things to learn to totally leverage its full power. I must say though, with the resources already out there, and thanks to the extremely helpful folks in the Delphi ECO newsgroup, I've not found this to be a barrier yet. Below are a smattering of links I've found especially useful:-

(0) comments

This page is powered by Blogger. Isn't yours?