topmost item in listbox

  • Thread starter Thread starter Guest
  • Start date Start date
Have a look at the TopIndex property of the ListBox. I don't think that the
ComboBox has an easy property like this.
 
You can get it, or set it, through pinvoke. The code below shows how to get
the top index for a ComboBox.

using System.Runtime.InteropServices;

private const int CB_ERR = -1;
private const int CB_GETTOPINDEX = 0x015b;
private const int CB_SETTOPINDEX = 0x015c;

[DllImport("User32.dll")]
private static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int
lParam);

....

int topIndex = SendMessage(this.comboBox1.Handle, CB_GETTOPINDEX, 0, 0);
if (topIndex != CB_ERR)
{
// Do something with "topIndex".
}
else
{
// Error
}
 
Back
Top