SmartPhone CF: Making custom control for a form; How do I make it 'selectable' like other cont

Hi,

You how how SmartPhone forms, you can use up/down to select between standard controls?

This doesn't seem to work if you use a custom control. When I select a custom control (user written/third party written) that I've added to a form, the up/down arrow key gets stuck on it.

I have created a workaround, but it is somewhat arcane. I was wondering if there was a better method?
#if (__SMARTPHONE__)
protected override void OnKeyDown(KeyEventArgs e)
{
//-
// HACK: This is to allow selection of previous and next controls before and after this custom control.
// TBD: This needs to be replaced with a SmartPhone official method.
//-

Control prevCtl = null;
Control nextCtl = null;
bool found = false;

// Find the modifyable controls immediately prior and afterwards this control.
foreach (Control c in this.Parent.Controls)
{
if (!(c is Label))
{
if (c == this)
{
found = true;
}
else if (!found)
{
prevCtl = c;
}
else if (nextCtl == null)
{
nextCtl = c;
}
}
}

// Select the previous or next control, depending on whether up or down was pressed.
if (e.KeyCode == Keys.Up)
{
if (prevCtl != null) prevCtl.Focus();
}
else
{
if (nextCtl != null) nextCtl.Focus();
}
}
#endif

[1390 byte] By [MarkRejhon] at [2007-12-16]
# 1

A minor correction. I had removed some code for simplicity reasons so the code is not exactly verbatim, but for simplicity, assume that this is the code to be executed on an up or down event. Other keypresses are actually handled, but I am excluding that since that's unnecessary extra info;

MarkRejhon at 2007-9-9 > top of Msdn Tech,Smart Device Development,.NET Compact Framework...
# 2

Mark,

It looks like you have the correct workaround. Since custom controls might be composed of other controls, the "keyboard" navigation is up to the custom control. Since NETCF V1 doesn't have TabIndex, it's hard to determine the next target for the Up/Down (V2 supports both TabIndex and TabStop).

-Chris

ChrisLorton at 2007-9-9 > top of Msdn Tech,Smart Device Development,.NET Compact Framework...