Wednesday, 23 May 2012

Grouping columns in a Infragistics Grid programmatically

Thanks Infragistics!
Okay, so I have a grid that I want to assign the data source to myself (it will change at run-time).
I would like the user to be able to define the columns that we group by (given the data, it might not be the column you see - for example by Customer means grouping by Customer ID, not Customer Name)
So, exactly how do you get the grid to do the grouping for you?
Well, it isn't as simple as you might think.
Take the following code: This is to bind a simple data set into the grid.

UltraGridBand band = new UltraGridBand("Band 0", -1); UltraGridColumn column1 = new UltraGridColumn("A", -1, null, 0, SortIndicator.Ascending, true); UltraGridColumn column2 = new UltraGridColumn("B", -1, null, 1, SortIndicator.Ascending, true); UltraGridColumn column3 = new UltraGridColumn("C", -1, null, 2, SortIndicator.Ascending, true); UltraGridColumn column4 = new UltraGridColumn("D"); column1.Header.VisiblePosition = 0;

column2.Header.VisiblePosition = 1; 
column3.Header.VisiblePosition = 2; 
column4.Header.VisiblePosition = 3; 
band.Columns.AddRange(new object[] { column1, column2,  column3, column4 }); band.GroupHeadersVisible = false; band.Header.Enabled = false; band.RowLayoutStyle = RowLayoutStyle.GroupLayout; 

You need to serialise the band into the grid with:
 ultraGrid1.DisplayLayout.BandsSerializer.Add(band); 

Set the group by style and put the data source into the grid.
ultraGrid1.DisplayLayout.ViewStyleBand = ViewStyleBand.OutlookGroupBy;
this.ultraGrid1.DisplayLayout.GroupByBox.Hidden = true;
ultraGrid1.DataSource = ds;
(here ds is a simple DataSet that contains 4 columns as you might guess from above)

So, this provides the grouping, yes?
Well, no.
The last parameter to the UltraGridColumn is to define whether it is a grouping column - changing this between true and false makes no odds.

So, what is the magic trick?
Around adding in the band into the BandsSerializer, you need to add
((ISupportInitialize)ultraGrid1).BeginInit();
ultraGrid1.DisplayLayout.BandsSerializer.Add(band); 

((ISupportInitialize)ultraGrid1).EndInit(); 
So blindingly obvious

Thursday, 26 May 2011

It's obvious - not

One of my pet hates is when people write code that is technically correct, but easily mis-understood.
I came across the following today that really grates me:

if (!(a <= 0 && a >= -2))
{ ...}

If you're great at boolean logic, then that's fine - but most people read it incorrectly and mis-interpret the meaning. It would be much more obvious to write it like this:

if (a < -2 || a > 0))
{ ...}

It says the same thing, but is easier to understand

Wednesday, 25 May 2011

iPhone's

Okay, so those that know me, I've been pretty much Windows through and through for many a year; well, finally last week I gave up on Windows mobile and turned to the iPhone.
So far, so good. The battery life seems slightly better than the LG phone I had and it is certainly more stable.
Had an interesting one today though, I wasn't getting any sound out of my iPhone. headphones worked fine, just the speakers weren't working.
Quick google around and it seemed like it was a relatively common problem requiring new hardware - didn't like the thought of that really. Then I remembered that I'd had my phone connected to my laptop when changing sounds settings on the laptop. Hmm, suddenly, I'm wondering if that is the cause.
So, I get home, connect the phone to the laptop and sync through iTunes. Then turn the sound back on on the laptop and sync again - hey presto, sound is now working on the phone.
So Apple, I think you need to think about how much information you sync between iTunes and the iPhone - this is certainly one setting I didn't expect to be synchronised (and unable to change on the phone!)

Friday, 20 November 2009

Hoax emails

Why do people continue to forward e-mails that claim the end of the world is nigh?
It seems to be almost a daily occurance now to receive an email asking you to forward it on to everyone you know as the worst virus ever is on its way and nobody knows how to get ride of it.

A simple Google of the headline of the story will soon tell you that it is a hoax!

Wednesday, 14 October 2009

VSTO and Due Dates on Tasks

You'd think that when you create a task that can have a blank due date, it would actually be blank now wouldn't you! Well, this isn't the case!
If you create a task and don't set a due date, the due date is actually set to 1/1/4501! This seems to be a magic date as other values (like DateTime.MaxValue) are shown literally.
This becomes a little cumbersome when you want to store the fact elsewhere.

Wednesday, 7 October 2009

VSTO and Contacts

I'm spending an amount of time looking at integrating our application into Outlook at the moment.

To give some background, I want to take the collection of contacts out of our database and put them into an Outlook Contact List - this is fine and easily done.
In fact there's a reasonable description of what is required here

What I then want to do is to make a note into our application when you send an email to one of these contacts; well that's pretty easy - or is it?

Attaching to the Application.ItemSend event is great, this tells us when we're about to send a message. From here, we can get the recipients of the message - that's fine.
We then need to get hold of the contact to see if it is one of our imported contacts.; well the recipient class has an AddressEntry property that has a GetContact method on it.

You'd think this would do the job for us now wouldn't you!
Well, it's like this...
If the contact is in a folder with the property set to be included in the address book, then yes, you can get at your imported contact. If the folder doesn't have this property set, then you don't!

I've spent a good few hours trying to track this down and the hint was on here as it says that it only returns the Contact in the address book.

Ho hum, it would be nice if this wasn't quite so obtuse, but there you go.