SQL Insert and Update specifications

Consider this scenario:

You have two tables, „Customer“ and „CustomerGroup“. Our customer table contains a foreign key „customergroup_FK“ to associate groups to our customers. Now we want to enable the user to delete some of our customer groups.

One time-consuming solution would be:

1. Delete the customer group,

2.select all customer where customergroup_FK fits our deletedGroup_PK

3.Update them for example to the NULL value.

Instead of this approach we can delegate this work directly to SQL Server:

Open your database diagram select „Relations“ and go to your „Customer_CustomerGroup“ relation. Now  on „UPDATE – and INSERT specifications“ select Delete Rule => set NULL

Now, since SQL Server do the update stuff for us, we only have to delete the customer group and maybe refresh the data source. That’s all. Very nice, isn’t it 🙂

Cheers!

Levels in XtraGrid

The DevExpress GridControl is such an awesome control. Specially the multi-level support is very useful when you want to display complex business objects. Anyway, sometimes you don’t want to display additional levels in your GridView to keep your UI clean. For this requirement use Grid Designer -> Feature Browser -> Data Binding -> ShowOnlyPredefinedDetails

Happy coding!

Restart 2.0

Today I asked myself about restarting a program by code correctly. We all know the Process class and can kill the program directly but that’s not very nice. After a little search I stumbled over the Application.Restart() method. I tested it and it works fine 🙂

Cheers!

XtraGrid FocusedRowChanging event

I wondered why there isn’t such an event in the DevExpress XtraGridView but there is, it’s just called BeforeLeaveRow

http://documentation.devexpress.com/#WindowsForms/DevExpressXtraGridViewsBaseColumnView_BeforeLeaveRowtopic

http://www.devexpress.com/Support/Center/Question/Details/S20137

It’s great for some validation code and if it fails you can just set e.Allow to false

Cheers!