Tuesday, September 25, 2007

Data controls ASP NET 2

When working with the data controls in ASP NET 2 - like GridView and DetailsView you are always best of if you use templated columns. The simplest way to acomplish this is to start of with DataBound fields then just right click them and choose "Convert to template field.

There are two major reasons for using templated fields:

1. You get predictable names, like CTL_MyView_TemplatefieldName - which is good if you need to access them via Javascript.

2. From code behind you can get your fields like this:

TextBox t = (TextBox) ((DetailsView)sender).FindControl("tbStatusDetailTemplate");

// Lazze

Sunday, September 09, 2007

Application Wide(Windows Forms) - capture Keys(like functions keys)

1) Define constants

const int WM_KEYDOWN = 0x100;
const int WM_KEYUP = 0x101;

2) Add interface, IMessageFilter

public partial class Form1 : Form, IMessageFilter

3) Make message interceptor

public bool PreFilterMessage(ref Message m)
{
Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode;
if (m.Msg == WM_KEYDOWN && keyCode == Keys.F8) // We'll just handle F8 here
{

MessageBox.Show("Key: " keyCode.ToString());
return true;
}
return false;
}

4) Add message interceptor to forms message handling(in Forms constructor)

Application.AddMessageFilter(this);

Enjoy!

//Lazze

Lazzes Smart Home - 2023

Here is an overview of the components in the Smart Home as of now. More stuff than I tought :-)