Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Deselect Row in ListBox

I have a MultiSelectSingle Listbox and an Edit Button. If the user selects a
line in the listbox it enables the Edit Button and highlights the line blue.
Is there a way to unhighlight the row if it is selected again? I have this
in the Listbox Click Event, but the event won't fire when I select the
highlighted row. Any ideas?

Private Sub lbxPreview_Click()

' load selected part info into controls
With lbxPreview
cboPartNumber = .List(.ListIndex, 0)
tbxQuantity = .List(.ListIndex, 2)
cboBilling = .List(.ListIndex, 4)

' enable or disable Edit button, and deselect listbox
If Not .ListIndex = -1 Then
cmbEditItem.Enabled = True
Else
.Value = Null
cmbEditItem.Enabled = False
End If
End With

' lock or unlock all controls except qty if items is going to be edited
cboPartNumber.Locked = cmbEditItem.Enabled
cboPartDescription.Locked = cmbEditItem.Enabled
cboBilling.Locked = cmbEditItem.Enabled

' only allow quantity to be changed
tbxQuantity.SetFocus

End Sub
--
Cheers,
Ryan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Deselect Row in ListBox

Try using a different _event:

Option Explicit
Dim CurIndex As Long
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub lbxPreview_MouseUp(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

With Me.lbxPreview
If CurIndex = .ListIndex Then
.ListIndex = -1
'reset anything you need to here
Else
'do the real work
End If
'prepare for next time
CurIndex = .ListIndex
End With
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
With Me.lbxPreview
.MultiSelect = fmMultiSelectSingle
For iCtr = 1 To 5
.AddItem "A" & iCtr
Next iCtr
.ListIndex = -1 'nothing selected
CurIndex = -1
End With
End Sub


Ryan H wrote:

I have a MultiSelectSingle Listbox and an Edit Button. If the user selects a
line in the listbox it enables the Edit Button and highlights the line blue.
Is there a way to unhighlight the row if it is selected again? I have this
in the Listbox Click Event, but the event won't fire when I select the
highlighted row. Any ideas?

Private Sub lbxPreview_Click()

' load selected part info into controls
With lbxPreview
cboPartNumber = .List(.ListIndex, 0)
tbxQuantity = .List(.ListIndex, 2)
cboBilling = .List(.ListIndex, 4)

' enable or disable Edit button, and deselect listbox
If Not .ListIndex = -1 Then
cmbEditItem.Enabled = True
Else
.Value = Null
cmbEditItem.Enabled = False
End If
End With

' lock or unlock all controls except qty if items is going to be edited
cboPartNumber.Locked = cmbEditItem.Enabled
cboPartDescription.Locked = cmbEditItem.Enabled
cboBilling.Locked = cmbEditItem.Enabled

' only allow quantity to be changed
tbxQuantity.SetFocus

End Sub
--
Cheers,
Ryan


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deselect a Commandbutton jnf40 Excel Programming 2 August 31st 10 08:06 AM
deselect rows Pam C Excel Discussion (Misc queries) 1 February 16th 06 09:39 PM
ActiveChart.Deselect won't Deselect Mark Stephens Charts and Charting in Excel 2 June 16th 05 02:54 AM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM


All times are GMT +1. The time now is 10:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"