Re: DirListBox question



On 18 Feb 2006 15:27:28 -0800, "Ether Jones"
<EtherJones@xxxxxxxxx> wrote:


Hello. Newbie here.

Trying to teach myself VB6 Pro, been reading a couple of books, writing
some "hello world" programs.

The problem I am having is that the books don't tell you what you CAN'T
do. So without the experience under my belt, I have no way of
knowing if what I'm trying to do is unreasonable.

So here's my question:

I want to be able to right-click on a folder in a DirListBox, and write
an event procedure for that action. Specifically, I want to grab that
folder's name and do something with it. I cannot figure out how to do
this. Is this something that is easily done, or have I already bumped
up against a limitation of the VB6 programming system? It seems like
a very obvious thing to want to do, which is why I am having a hard
time imagining that Bill Gates didn't think of it already.

Can someone please tell me if this is easily done, and if so, how?

Hi. The two answers you have received so far apparently offer
suggestions contrary to what you wish to do. According to the
above you want to use the right (presumably the secondary) mouse
button. That's easy:

Private Sub Dir1_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)

If Button = 2 Then
If Dir1.ListIndex <> -1 Then
MsgBox Dir1.List(Dir1.ListIndex)
End If
End If
End Sub

However there is a problem with the Directory List Box in that
when you point at it with the mouse cursor on the entry you wish
to select and then hit the secondary mouse button, the entry you
clicked on (the ListIndex) is not selected. One must click on the
entry with the left (primary) mouse button to chance the DirBox's
ListIndex.

The other issue is which mouse button is considered the "right"
one. For a left-handed person, the right mouse button will be the
primary button, and the left button will be the secondary button:
Windows Control Panel allows the user to swap mouse buttons.
Fortunately, it looks like Visual BASIC uses the value of 1 as the
primary (default left) and 2 as the secondary (default right).

There *MUST* be a way to move the DirBox's ListIndex to where the
mouse pointer is when the secondary (right) button is depressed.
It can be done by using the MouseDown event's "Y" position value.
Let's see.

You will need to know how many Twips each entry in the Directory
List Box is in height. So set a Lable control to the same font and
font size as the Dir control. Set the Lable control's AutoSize to
TRUE and leave the Lable's Caption to "Label1"

The Dir box's top border takes up a few twips: more if the
Appearance is 3D, less if it is flat.

The "Y" position's offset starts at the top of the Dir box. So all
we need do is examine the MouseDown event's Y value, add the Dir
box's border value, and divide by the height of the Label control.

----------- test -------------

Option Explicit

Dim EntryHeight As Integer, EntryOffset As Integer

Private Sub Dir1_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)

Dim Temp As Integer
If Button = 2 Then
Temp = (Y + EntryOffset) / EntryHeight
Dir1.ListIndex = Temp
MsgBox Dir1.List(Dir1.ListIndex)
End If
End Sub

Private Sub Form_Load()
EntryHeight = Label1.Height

If Dir1.Appearance = 1 Then
EntryOffset = Screen.TwipsPerPixelY * 4
Else
EntryOffset = Screen.TwipsPerPixelY + 2
End If
End Sub

----------- test -------------

Well that is odd: The ListIndex value is not the real ListIndex
value! The DirListBox control utterly ignores the entries that
show parent directories. I wonder if there is a work-around.


Thanks.
EJ

---
Dan Adamson for Idaho governor: finally, a Republican
who might not betray us! http://www.myidahorocks.com
.



Relevant Pages

  • Re: Setting ListIndex
    ... ' Advances the argument combo box to the next entry in its list, ... ' and returns the ListIndex value of that entry. ... RetreatCombo = lngPrevious ... Private Sub cmdComboDown_Click ...
    (microsoft.public.access.formscoding)
  • Re: Setting ListIndex
    ... ' Advances the argument combo box to the next entry in its list, ... ' and returns the ListIndex value of that entry. ... RetreatCombo = lngPrevious ... Private Sub cmdComboDown_Click ...
    (microsoft.public.access.formscoding)
  • Re: ContentControlOnExit
    ... Private bNoReset As Boolean ... Private Sub Document_Open ... MsgBox "Invalid Entry." ... control, ...
    (microsoft.public.word.vba.general)
  • RE: forms - how to fill each line in a record
    ... You have to write event code for the control to transfer the data from the ... control to the cell on the worksheet. ... Private Sub CommandButton1_Click ... How does that work when you use the data entry tools on the FORMS toolbar? ...
    (microsoft.public.excel.programming)
  • Re: Pop up message
    ... >control to be in capital letters? ... >simply by forcing the user's entry into caps. ... > Private Sub txtMyTextBox_AfterUpdate ...
    (microsoft.public.access.forms)