K
Kevin Westhead
I'm working on a virtual list-view control derived from
System.Windows.Forms.ListView, however I've been running into problems
because the base control thinks it owns the items in the list. For example,
I get the following exception whenever the control receives focus:
Specified argument was out of the range of valid values.
Parameter name: '5' is not a valid value for 'displayIndex'.
at System.Windows.Forms.ListViewItemCollection.get_Item(Int32
displayIndex)
at System.Windows.Forms.ListView.get_FocusedItem()
at System.Windows.Forms.ListView.WndProc(Message& m)
at VListView.WndProc(Message& m) in ..\listview.cs:line 355
The code for the base control, in response to WM_SETFOCUS, is something like
this:
base.WndProc(m);
if ((this.FocusedItem != null) || (this.Items.Count <= 0))
return;
this.Items[0].Focused = true;
return;
The FocusedItem property is as follows:
int num1;
if (base.IsHandleCreated)
{
num1 = base.SendMessage(4108, -1, 1); // LVM_GETNEXTITEM
if (num1 > -1)
return this.Items[num1];
}
return null;
It looks to me as though 'this.Items.Count' should be tested first in
response to WM_SETFOCUS in order to prevent the control from trying to
retrieve an item from a non-existent collection. My workaround is to call
'base.DefWndProc' in the derived control in response to WM_SETFOCUS. I have
also come across problems in OnHandleDestroyed, which again seems to assume
that if there is a selection then there must also be a valid
ListViewItemCollection.
Has anyone else run into these problems? Is it just a case of working around
the assumptions made in System.Windows.Forms.ListView or am I missing a step
when setting up my virtual list-view that would avoid these problems?
TIA.
System.Windows.Forms.ListView, however I've been running into problems
because the base control thinks it owns the items in the list. For example,
I get the following exception whenever the control receives focus:
Specified argument was out of the range of valid values.
Parameter name: '5' is not a valid value for 'displayIndex'.
at System.Windows.Forms.ListViewItemCollection.get_Item(Int32
displayIndex)
at System.Windows.Forms.ListView.get_FocusedItem()
at System.Windows.Forms.ListView.WndProc(Message& m)
at VListView.WndProc(Message& m) in ..\listview.cs:line 355
The code for the base control, in response to WM_SETFOCUS, is something like
this:
base.WndProc(m);
if ((this.FocusedItem != null) || (this.Items.Count <= 0))
return;
this.Items[0].Focused = true;
return;
The FocusedItem property is as follows:
int num1;
if (base.IsHandleCreated)
{
num1 = base.SendMessage(4108, -1, 1); // LVM_GETNEXTITEM
if (num1 > -1)
return this.Items[num1];
}
return null;
It looks to me as though 'this.Items.Count' should be tested first in
response to WM_SETFOCUS in order to prevent the control from trying to
retrieve an item from a non-existent collection. My workaround is to call
'base.DefWndProc' in the derived control in response to WM_SETFOCUS. I have
also come across problems in OnHandleDestroyed, which again seems to assume
that if there is a selection then there must also be a valid
ListViewItemCollection.
Has anyone else run into these problems? Is it just a case of working around
the assumptions made in System.Windows.Forms.ListView or am I missing a step
when setting up my virtual list-view that would avoid these problems?
TIA.