Really Achieving your Childhood Dreams

- Monday, October 08, 2007

Randy Pausch, a Computer Sciences professor at Carnegie Mellon University has received very high media coverage for his "Last Lecture" at university, because he is diagnosed with pancreatic cancer - having a couple of months left.

Without being sensational about his illness, if you are into personal development or have ever thought about what happened to your childhood dreams, this is a must-see.

The full 90 min video can be found here. And his website is here.

Labels:


Trouble with the ListView SelectedIndexChanged event

I've been messing with a System.Windows.Forms.ListView control lately. I have a list of items in a standard ListView control. If the user selects an item, I have some other controls to be shown. If the user deselects the item in the ListView I want these other controls to be hidden.

Now, whenever a user changes the selected item in the ListView control, the SelectedIndexChanged event is called twice: once for deselecting the item (SelectedItems.Count == 0) and once for selecting the new item. This causes the "other controls" to flicker: they first get hidden, then show up again.

Despite some existing solutions using a Timer (here) I analyzed the available events of a ListView. Click and MouseClick are useless since they only occur when the user clicks an item, not when deselecting. MouseUp looks promising since it also fires when the user clicked somewhere outside the items. I have not found a key stroke to deselect an item in a ListView, so MouseUp should be sufficient to check for deselection.

Using that I create a new ListViewEx derived from ListView with two need events: ItemsDeselected and ItemSelected. The originally SelectedIndexChanged event is left untouched.

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;

namespace Instyler.Controls
{
class ListViewEx : ListView
{
private bool _enableDeselectionEvent = false;

protected override void OnSelectedIndexChanged( EventArgs e )
{
_enableDeselectionEvent = ( SelectedItems.Count == 0 );

if ( SelectedItems.Count != 0 )
OnItemSelected( this, new EventArgs() );

base.OnSelectedIndexChanged( e );
}


protected override void OnMouseUp( MouseEventArgs e )
{
if(_enableDeselectionEvent)
OnItemsDeselected( this, new EventArgs() );

base.OnMouseUp( e );
}


#region Our new events

public delegate void ItemsDeselectedHandler( object sender, EventArgs e );

[Description("Event raised when items got deselected"), Category("Behavior")]
public event ItemsDeselectedHandler ItemsDeselected = null;
protected virtual void OnItemsDeselected( object sender, EventArgs e )
{
if ( ItemsDeselected != null )
ItemsDeselected( sender, e );
}


public delegate void ItemSelectedHandler( object sender, EventArgs e );
[Description("Event raised when a new item got selected."), Category("Behavior")]
public event ItemSelectedHandler ItemSelected = null;
protected virtual void OnItemSelected( object sender, EventArgs e )
{
if ( ItemSelected != null )
ItemSelected( sender, e );
}

#endregion
}
}

Feel free to use that code.

Labels:


Automatic shutdown if no client is available

- Saturday, May 12, 2007

I have a home file server that shall not run 24/7. So I enabled Wake-On-Lan which was working great. What I missed was some kind of Shutdown-On-Idle. After a little thought I came up with the idea that the server may shutdown when all possible clients are no longer available. So I wrote a little DOS batch script that pings all clients and shuts down the server when there is no one available.

Here's the script:

@echo off

CALL :ping client1
CALL :ping client2

ECHO SHUTTING DOWN IN 30 SECONDS
psshutdown -s -f -t 30
GOTO :EOF

:ping
ECHO Pinging %1 ...
PING -n 1 -w 3000 %1 |find "Reply"
IF errorlevel 1 GOTO :EOF
ECHO %1 is online. Not shutting down...
EXIT

Just save it as a .bat file and schedule it to run every hour or so. I used psshutdown.exe instead of the standard windows shutdown.exe because that one cause an error on my server.

Labels:


Kent Beck talking about "ease at work"

- Sunday, December 24, 2006

Here is a chance to view Kent Beck in a video. It's a talk he gave at a special event in San Francisco on May 26, 2006.

Kent Beck, the inventor of Extreme Programming, is talking about the "ease at work". I think he means the "Flow" state, a kind of positive stress where you just work on the thing you want without arguing about the world around you. There is a good book about the Flow state (Amazon) that describes the whole thing from a philosophical view.

The video is about an hour long. Watch it here.

Labels: