473,470 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ListBox read item on double click

8 New Member
Hi,

I have a list box where I am reading information from a MS Access Database.
The list box populates when the form is loaded. However, sometimes the information is wider than the list box. I have added scroll bars so user can see the information. However, It would be great if they didn't need to scroll.

I've read that listboxes cannot wrap text so, is there a way to use a double click event on a item to readthat line from the list box and display it in another text field so i can use the mutliline function? Or even better after the item is double clicked a pop up form will appear with the item

Thanks in advance, i hope that made sense
Nov 21 '06 #1
3 4989
albertw
267 Contributor
Hi,

I have a list box where I am reading information from a MS Access Database.
The list box populates when the form is loaded. However, sometimes the information is wider than the list box. I have added scroll bars so user can see the information. However, It would be great if they didn't need to scroll.

I've read that listboxes cannot wrap text so, is there a way to use a double click event on a item to readthat line from the list box and display it in another text field so i can use the mutliline function? Or even better after the item is double clicked a pop up form will appear with the item

Thanks in advance, i hope that made sense
hi

this might be a solution

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  3.  
  4. Private Const LB_ITEMFROMPOINT = &H1A9
  5. Dim ndx As Long
  6.  
  7. Public Function ListBoxHit(ListBox As ListBox, ByVal X As Single, ByVal Y As Single) As Long
  8.     ndx = SendMessage(List1.hWnd, LB_ITEMFROMPOINT, 0, (Y \ Screen.TwipsPerPixelY) * 65536 + (X \ Screen.TwipsPerPixelX))
  9.     If (ndx And &H10000) = &H10000 Then
  10.         ListBoxHit = -1
  11.     Else
  12.         ListBoxHit = ndx
  13.     End If
  14. End Function
  15.  
  16. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  17. Label1.Visible = False
  18. End Sub
  19.  
  20. Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  21. If Button = 2 Then
  22.   ndx = ListBoxHit(List1, X, Y)
  23.   If Not ndx = -1 Then List1.Selected(ndx) = True
  24.   With Label1
  25.   .Move List1.Left + List1.Width, List1.Top + Y - 60
  26.   .Caption = " " & List1.List(ndx) & " "
  27.   .Visible = True
  28.   End With
  29. Else
  30. Label1.Visible = False
  31. End If
  32. End Sub
  33.  
  34.  
  35.  
the listbox = List1
the label=Label1
create:
visible=false
backstyle=opaque
autosize=true
borderstyle=fixed single
backcolor= any color

click with right mouse on a list.item will trigger the label to pop-up
Nov 21 '06 #2
jdwyer05
8 New Member
albertw,

Im still having problems reading the events, the code you provided does implement the click event. However, it will only read the first item int he list box.
for example:

if i have a list with the records 1,2,3,4,5 and i click on 5 it will still display the record for number 1.


hi

this might be a solution

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  3.  
  4. Private Const LB_ITEMFROMPOINT = &H1A9
  5. Dim ndx As Long
  6.  
  7. Public Function ListBoxHit(ListBox As ListBox, ByVal X As Single, ByVal Y As Single) As Long
  8.     ndx = SendMessage(List1.hWnd, LB_ITEMFROMPOINT, 0, (Y \ Screen.TwipsPerPixelY) * 65536 + (X \ Screen.TwipsPerPixelX))
  9.     If (ndx And &H10000) = &H10000 Then
  10.         ListBoxHit = -1
  11.     Else
  12.         ListBoxHit = ndx
  13.     End If
  14. End Function
  15.  
  16. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  17. Label1.Visible = False
  18. End Sub
  19.  
  20. Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  21. If Button = 2 Then
  22.   ndx = ListBoxHit(List1, X, Y)
  23.   If Not ndx = -1 Then List1.Selected(ndx) = True
  24.   With Label1
  25.   .Move List1.Left + List1.Width, List1.Top + Y - 60
  26.   .Caption = " " & List1.List(ndx) & " "
  27.   .Visible = True
  28.   End With
  29. Else
  30. Label1.Visible = False
  31. End If
  32. End Sub
  33.  
  34.  
  35.  
the listbox = List1
the label=Label1
create:
visible=false
backstyle=opaque
autosize=true
borderstyle=fixed single
backcolor= any color

click with right mouse on a list.item will trigger the label to pop-up
Nov 29 '06 #3
jdwyer05
8 New Member
It looks like ndx is not updating with the correct selected record. B/c if you just enter an integer value into the .Caption = " " & List1.List(ndx) & " " it will display the record corresponding to that value. So it seems to be that ndx is constantly remaining the value 0.




albertw,

Im still having problems reading the events, the code you provided does implement the click event. However, it will only read the first item int he list box.
for example:

if i have a list with the records 1,2,3,4,5 and i click on 5 it will still display the record for number 1.
Nov 29 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Bill | last post by:
I'm trying to create a wizardlike interface using a couple listboxes. I know you've seen it before. You double click on an item in one listbox and it "moves" it to the other. I used to approach...
1
by: Blacky | last post by:
Hi I have a small form with a listbox. When double clicking on an item, the item is added to another form and then the form is closed. But this creates an exception error saying that the ListBox...
1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
1
by: Zyrthofar Blackcloak | last post by:
Hi everyone I have a listbox with more items in it than is printed on screen. I need the index number of the first shown item to move another listbox to the same position... Explained differently,...
18
by: Zytan | last post by:
I want the same function to be run whether you press Enter or double click the listbox. It seems really verbose to write both handlers to both events everytime, even if they both call the same...
4
by: Jeff User | last post by:
Hi Using .NET 1.1, C#, web app I (actually our client) would like to be able to double click a selection in a listbox and have it postback to server . There I would want to access the item that...
5
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that...
1
by: jasydnor | last post by:
Hi, New to the forums and have a question. I've only been developing for about five months now so I apologize if this seems oversimplistic....I am writing a program on an idea I had on a whim. ...
8
by: jh | last post by:
I'd like to copy/paste into a listbox during runtime. I can do this for a textbox but can't figure out how to accomplish this for a listbox. Any help? Thanks.
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.