Back from the dead

- Thursday, March 13, 2008

Unfortunally my ex- hosting provider did not pay the bills for my domain so it suddenly went down. After about 5 domain grabbers tried to use it for advertising, I finally got it back. I lost to pics from the old site, but new posts will be coming shortly...

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:


My new car! Nissan Qashqai

- Tuesday, July 17, 2007

Here's my latest investment: A Nissan Qashqai 2.0 Tekna incl. Executive Package. Color "Hazy Gold" - well, it's more like "Mustard" or "Sand". :-)
First 50km: I love it.




Labels: