combo box selection

  • Thread starter Thread starter george
  • Start date Start date
G

george

Hi,

I use the following code (kindly provided by Dan Artuso)
to select the whole text in a text box when I click in it:

Static bSelectAll As Boolean
If Not IsNull(Me.MyTextbox) And Not bSelectAll Then
Me.MyTextbox.SelStart = 0
Me.MyTextbox.SelLength = Len(Me.MyTextbox)
bSelectAll = True
Else
bSelectAll = False
End If

This works fine. However when I tried to apply the code to
a combo box it didn't work. Any clues?

Thanks a lot in advance, george
 
Doesn't selecting an item from the list give the
appearance of selecting the entire item?
Geof.
 
george said:
I use the following code (kindly provided by Dan Artuso)
to select the whole text in a text box when I click in it:

Static bSelectAll As Boolean
If Not IsNull(Me.MyTextbox) And Not bSelectAll Then
Me.MyTextbox.SelStart = 0
Me.MyTextbox.SelLength = Len(Me.MyTextbox)
bSelectAll = True
Else
bSelectAll = False
End If

This works fine. However when I tried to apply the code to
a combo box it didn't work. Any clues?


Since a combo box's value is determined by its BoundColumn
but its displayed text is determined by the first non-zero
ColumnWdth, you most likely need to use the combo box's Text
property instead of its Value property.

Me.MyTextbox.SelLength = Len(Me.MyTextbox.Text)
 
Hi again,

Thank you for your reply. No offense! I just didn't
believe that once you answered my question you would check
again for replies.

Well I did what you suggested. To be exact I used the
following code:

Static bSelectAll As Boolean
If Not IsNull(Me.MyCombobox) And Not bSelectAll Then
Me.MyCombobox.SelStart = 0
Me.MyCombobox.SelLength = Len(Me.MyCombobox.Text)
bSelectAll = True
Else
bSelectAll = False
End If


when I clicked in the combo box the text was not selected
and I don't have any clue why not

Thanks again, george
 
george said:
I used the following code:

Static bSelectAll As Boolean
If Not IsNull(Me.MyCombobox) And Not bSelectAll Then
Me.MyCombobox.SelStart = 0
Me.MyCombobox.SelLength = Len(Me.MyCombobox.Text)
bSelectAll = True
Else
bSelectAll = False
End If

when I clicked in the combo box the text was not selected
and I don't have any clue why not

Sorry, I missed that you want this to happen when you click
into the combo box. What I posted would work if you got to
the combo box by using the Tab key.

The reason that doesn't work for clicking is that a mouse
click is supposed to position the cursor within the text or
select all or a portion of the text (according to the
windows standard). So, after the code selects all the text,
the click positions the cursor to the point of the click,
making the code useless in this situation.

The only way I can think of to overcome the standard mouse
processing is to place a transparent command button on top
of the combo box. Then use the buttons GotFocus event to
swith the focus to the combo box:

Me.MyCombobox.SetFocus
Me.MyCombobox.SelStart = 0
Me.MyCombobox.SelLength = Len(Me.MyCombobox.Text)
 
Back
Top