Ever needed to bind an enum to a control, like a dropdownlist? Needed to do this earlier, and came across this article on DeveloperFusion. The problem with binding a control to a hashtable though, is that you lose the ordering in the enum.

Tried using some alternatives, such as the SortedList, without any luck – the problem with using a SortedList is that there is no way to sort by the value property.

Eventually, I settled on using an ArrayList…

enum MyEnum
{
First = 1,
Second = 2,
Third = 3,
Last = 99
}
private IList GetEnum(Type type)
{
string[] names = Enum.GetNames(type);
Array values = Enum.GetValues(type);
IList list = new ArrayList();

for (int i = 0; i

This created the desired result of populating the dropdownlist items in the same order as they appeared in the enum.

Although I’ve read quite a few horror stories about Dell Support, where people were put through to call center staff in India and had all sorts of trouble, my experience has been very good, though this may have been due to the fact that it was a server that went wrong (and hence, I was speaking to the server technical support team).

We had one of our servers die unexpectedly one morning, resulting in a call to Dell support. Got through to a support technician after about 6 minutes waiting, and began running through the usual set of diagnostics tests, as advised by the tech support dude – checking for lights, disconnecting memory, hard disks, etc. Nothing worked.

New parts arrived 9am the next morning. An engineer was here by 3pm, and the server was fully sorted out within 45 minutes. Turned out to be a power issue, and replacing the motherboard and power-lead sorted the problem.

A really nice touch was a call from tech support dude the next day to check if everything was sorted out. That’s what I call service.

Overall, I’m very impressed and wouldn’t hesitate to buy from Dell again.

Some time ago, I blogged about collapsing & expanding regions in VS.NET. The best solution at the time was to use the standard VS.NET shortcuts for outlining – Ctrl+M, Ctrl+M to fold or unfold the current code block, Ctrl+M, Ctrl+L to unfold all code blocks, and Ctrl+M, Ctrl+O to fold all code blocks.

This works, with the only downside being that when using the latter two shortcuts, all collapsible elements are collapsed, rather than just regions (#region… #endregion).

Fortunately, Roland Weigelt has blogged about better support for #region… #endregion, and written a little VS.NET macro which will only expand or collapse region code blocks (as opposed to all elements).

Get the macros and installation instructions on Roland’s blog! :-)

Don’t know where I picked up this SQL code snippet to change the owner of all objects in a database to ‘dbo’ but it’s been a great timesaver time and time again :-)

declare @ObjectName varchar(256)
-- we are only interested in USER Objects
-- not already owned by 'sa'
-- we don't want keys and constrainst
set @ObjectName = (
select top 1 [name] from sysobjects where uid <> SUSER_SID('sa') and [type] in ('FN','IF','P','TF','U','V'))
declare @ObjectOwner varchar(256)
declare @ObjectFullName varchar(512)
declare @NewOwner varchar(256)
set @NewOwner = 'dbo'

-- default to 'dbo' if null
set @NewOwner = isnull(@NewOwner, 'dbo')

while @ObjectName is not null
begin
	select @ObjectOwner = USER_NAME(uid) from sysobjects where [name] = @ObjectName
	set @ObjectFullName = @ObjectOwner + '.' + @Objectname
	PRINT 'Changing ownership of ''' + @Objectname + ''' from ''' + @ObjectOwner + ''' to ''' + @NewOwner + ''''
	execute sp_changeobjectowner @ObjectFullName, @NewOwner
	set @ObjectName = (select top 1 [name] from sysobjects where uid <> SUSER_SID('sa') and [type] in ('FN','IF','P','TF','U','V'))
end

Thank you to the author, wherever/whoever you are! :-)

Update: Looks like I probably picked this up at Darrell Norton’s Blog.