Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Thanks in advance....While I am click the button automatically the mouse pointer went to the 1st item in checklistbox and focus it using c#.net

What I have tried:

chkLBDestinationFolder.SelectedIndex = 0;
not get works
Posted
Updated 26-Feb-21 5:48am
v3
Comments
Member 15028582 25-Feb-21 2:01am    
I got a output....

chkLBDestinationFolder.TopIndex = 0;

But is this a correct code....
[no name] 26-Feb-21 15:12pm    
It's a contest between "move mouse", "select an item", or both.

try it with :
VB
CheckedListBox1.SelectedItem = CheckedListBox1.Items(yourIndex)


... but the CheckedListBox1.SelectedIndex must also work in the same way ...
 
Share this answer
 
v2
Is this what you wanted? I basically just followed the instructions in your question!

C#
private void Button_Click(Object sender, EventArgs e) {
  Int32 index = 0;  // or any other valid index
  // select an item, scroll into view
  clbx.SelectedIndex = index;
  clbx.Focus();
  // move the mouse cursor
  Rectangle r = clbx.GetItemRectangle(clbx.SelectedIndex);
  Point newPointerPosition = clbx.PointToScreen(r.Location);  // top left corner of the item
  newPointerPosition.Offset(r.Width / 2, r.Height / 2);       // centre of the item
  Cursor.Position = newPointerPosition;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900