Link to home
Start Free TrialLog in
Avatar of KOCUBA
KOCUBA

asked on

Combo box and highlighting

I have a number of combo  boxes on a form.  When I display this form all of the data, in each of the boxes, in the form are highlighted.  How can I get this not to happen?  it is really starting to irratate me.

Dave
Avatar of smegghead
smegghead
Flag of United Kingdom of Great Britain and Northern Ireland image

You can set the listindex property to -1 which will deselect any selection.
Avatar of vigdis
vigdis

If All of the data in a combobox are highlighted i would check the forecolor and backcolor properties of the control.
Avatar of KOCUBA

ASKER

Ok sorry it is still a little early.  I guess what I should have said is I load the combo box with additem then I set the text  property to a value from a database that would be a selection in the list of loaded values.  The text that I set it equal to is what is highlighted.

smegghead,  I tried your suggestion and it did not change anything.

viqdis,  I hope my above clarification helps

Sorry Again
Dave
set the selstart and sellength properties of the combobox to 0..

is this a bound combobox ???

Smegg
Try this:

Put a picturebox to the form.
Set those picturebox properties:
  Appearance = 0 - Flat
  Borderstyle = 0 -None
  Backcolor = Backcolor of the form

In the Clik  event of the
combobox put this line:

Picture1.SetFocus

Int the Lostffocus event of the combo:

 Combo2.BackColor = vbWhite
 Combo2.ForeColor = vbBlack
Avatar of KOCUBA

ASKER

smegghead,  I've tried setting those prpoerties to zero and that did not work.  Also this is not a bound cbombobox.

viqdis
That did not work either.
What is the style of the combobox ???

If I put of combobox on my screen, it only highlights the text when the control has focus.

not sure what's happening on yours..
Avatar of KOCUBA

ASKER

smegghead,
The style is 0 - Dropdown Combo.

Usually that is what happens with mine.  But when this form loads I have 6 different combo boxes all of which are highlighted.

hmmm, strange !!!

can you post the .frm contents here .. or is it too complex ??
Avatar of KOCUBA

ASKER

Was just thinking about doing that here is the sub that loads all the fields on the form.  The comboboxes are right near the beginning.

Thanks for all the help.

Public Sub Load_Fields()
    On Error GoTo Load_Fields_Err
   
    Dim intI As Integer
    txtDistNo.Text = g_config.lngDistNo
    intI = 0
    While arrDistType(intI, 0) <> g_config.strDistType
        intI = intI + 1
    Wend
    txtDistType.Text = arrDistType(intI, 1)
    txtName.Text = g_config.strDistName
    txtAddress(0).Text = g_config.strAddr1
    txtAddress(1).Text = g_config.strAddr2
    txtCity.Text = g_config.strCity
    txtState.Text = g_config.strState
    txtZip.Text = g_config.strZip
    If g_config.strCountry <> "" Then
        intI = 0
        While arrCountryCodes(intI, 0) <> g_config.strCountry
            intI = intI + 1
        Wend
        cboCountry.Text = arrCountryCodes(intI, 1)
    End If
    intI = 0
    While arrCountryCodes(intI, 0) <> ""
        cboCountry.AddItem arrCountryCodes(intI, 1)
        intI = intI + 1
    Wend
    intI = 0
    While MiscCode(intI, 0) <> ""
        cboMisc1.AddItem MiscCode(intI, 1)
        cboMisc2.AddItem MiscCode(intI, 1)
        cboMisc3.AddItem MiscCode(intI, 1)
        cboMisc4.AddItem MiscCode(intI, 1)
        intI = intI + 1
    Wend
    If g_config.strMiscType1 <> "" Then
        intI = 0
        While MiscCode(intI, 0) <> g_config.strMiscType1
            intI = intI + 1
        Wend
        cboMisc1.Text = MiscCode(intI, 1)
    End If
    txtMisc1.Text = g_config.strMiscValue1
    intI = 0
     
    If g_config.strMiscType2 <> "" Then
        intI = 0
        While MiscCode(intI, 0) <> g_config.strMiscType2
            intI = intI + 1
        Wend
        cboMisc2.Text = MiscCode(intI, 1)
    End If
    txtMisc2.Text = g_config.strMiscValue2
    If Not IsNull(g_config.strMiscType3) Then
        intI = 0
        While MiscCode(intI, 0) <> g_config.strMiscType3
            intI = intI + 1
        Wend
        cboMisc3.Text = MiscCode(intI, 1)
    End If
    txtMisc3.Text = g_config.strMiscValue3
    If g_config.strMiscType4 <> "" Then
        intI = 0
        While MiscCode(intI, 0) <> g_config.strMiscType4
            intI = intI + 1
        Wend
        cboMisc4.Text = MiscCode(intI, 1)
    End If
   
    txtMisc4.Text = g_config.strMiscValue4
    intI = 0
    While arrLanguage(intI, 0) <> ""
        cboLanguage.AddItem arrLanguage(intI, 1)
        intI = intI + 1
    Wend
    intI = 0
    While arrLanguage(intI, 0) <> g_config.strLangCode
        intI = intI + 1
    Wend
    cboLanguage.Text = arrLanguage(intI, 1)
    txtMatcoWeekNo.Text = g_config.lngMatcoWeekNo
    txtWeeksInBusiness.Text = g_config.lngWeeksInBusiness
    intI = 0
    While arrDayofWeek(intI, 0) <> g_config.lngShipDay
        intI = intI + 1
    Wend
    txtShipDay.Text = arrDayofWeek(intI, 1)
    intI = 0
   
    While arrJurisdictions(intI, 0) <> ""
    cboJurisdiction.AddItem arrJurisdictions(intI, 1)
    intI = intI + 1
    Wend
    intI = 0
    While arrJurisdictions(intI, 0) <> g_config.lngJurisdictionNo
        intI = intI + 1
    Wend
    cboJurisdiction.Text = arrJurisdictions(intI, 1)
    txtStatementPercent.Text = g_config.dblStatementPercent
    txtMaxTPLongTerm.Text = g_config.dblMaxTPLongTerm
    txtCustCreditLimit.Text = g_config.dblCustCreditLimit
    txtNoDaysLockPSAQuote.Text = g_config.lngNoDaysLockPSAQuote
    txtDelNotesKeepDays.Text = g_config.lngDelNotesKeepDays
    txtPkgLstRetentionDays.Text = g_config.lngPkgLstRetentionDays
    txtTPTurns.Text = g_config.dblTPTurns
    txtMinTPPayment.Text = g_config.dblMinTPPayment
    txtNSFChargeAmt.Text = g_config.dblNSFChargeAmt
    txtStmtFeeDesc.Text = g_config.strStmtFeeDesc
    chkPrintPSARemit.Value = g_config.bolDayPrintPSARemit
    txtAppRetentionDays.Text = g_config.lngAppRetentionDays
    sschkElecFundsXfer.Value = g_config.bolElecFundsXfer
    sschkHistOnRouteList.Value = g_config.bolHistOnRouteList
    sschkDispCredLimWarn.Value = g_config.bolDispCredLimWarn
    sschkAdjustWkPay.Value = g_config.bolAdjustWkPay
    sschkXmitPSAPmtData.Value = g_config.bolXmitPSAPmtData
    sschkPrintProspects.Value = g_config.bolPrintProspects
    sschkBalOnlyOnRouteList.Value = g_config.bolBalOnlyOnRouteList
    Select Case Trim(g_config.strReportCustomersType)
    Case "A"
        optReportCustomers(1).Value = True
    Case "S"
        optReportCustomers(0).Value = True
    Case Else
        optReportCustomers(2).Value = True
    End Select
    txtMinSkipBalance.Text = g_config.dblMinSkipBalance
    sschkTermsAndConditions.Value = g_config.bolTermsAndConditions
    sschkSigOnReceipt.Value = g_config.bolSigOnReceipt
    sschkFormFeedAfterReceipt.Value = g_config.bolFormFeedAfterReceipt
    sschkPhNoOnReceipt.Value = g_config.bolPhNoOnReceipt
    sschkPrintAddrOnReceipt.Value = g_config.bolPrintAddrOnReceipt
    txtNoReceiptsDown.Text = g_config.lngNoReceiptDown
    txtNoReceiptsAcross.Text = g_config.lngNoReceiptsAcross
    sschkOnHandWarn.Value = g_config.bolOnHandWarn
    sschkFullInvtMaint.Value = g_config.bolFullInvtMaint
    sschkPrintOnlyInvtItems.Value = g_config.bolPrintOnlyInvItems
    sschkBldReOptItemsOrder.Value = g_config.bolBldReOpItemsOrder
    sschkBldPromoOrder.Value = g_config.bolBldPromoOrder
    txtRemSentOrdersDays.Text = g_config.lngRemSentOrderDays
    txtStdTradeInMarginPercentage.Text = g_config.dblStdTradeInMargPercentage
    txtNoDaysRemRegOrders.Text = g_config.lngNoDaysRemRegOrders
    txtNoDaysRemSpecOrders.Text = g_config.lngNoDaysRemSpecialOrders
    Select Case g_config.strValueInvType
    Case ""
        optValueInvtType(0).Value = True
    Case "LAST"
        optValueInvtType(1).Value = True
    Case Else
        optValueInvtType(2).Value = True
    End Select
    txtMarketingMessage.Text = g_config.strMarketingMessages
    sschkSendWklyToMatco.Value = g_config.bolSendWklyToMatco
    sschkAcceptMsgWhenSending.Value = g_config.bolAcceptMsgWhenSending
    sschkToolTips.Value = g_config.bolToolTips
    txtSysInfoCollectionDate.Text = g_config.dtmSysInfoCollection
    txtSysInfoIntervalDays.Text = g_config.lngSysInfoIntervalDays
    txtNextBuildNo.Text = g_config.lngOrderBuildNo
    txtLastInvMiscSlsPrint.Text = g_config.lngLastInvMiscSlsPrint
    txtLastInvTradeInPrint.Text = g_config.lngLastInvTradeInPrint
    txtLastInvAdjPrint.Text = g_config.lngLastInvAdjPrint
    txtLastPSARemBatch.Text = g_config.strLastPSARemBatch
    txtNextPSABatchNo.Text = g_config.lngNextPSABatchNo
    txtNextCustNo.Text = g_config.lngNextCustNo
    txtNextPkgListNo.Text = g_config.lngNextPkgListNo
    txtBusinessUnit.Text = g_config.strBusinessUnit
    txtMonthCloseDate.Text = g_config.dtmMonthClose
    txtWeekCloseDate.Text = g_config.dtmWeekClose
    txtYearCloseDate.Text = g_config.dtmYearClose
    lblVersionNo.Caption = lblVersionNo.Caption & g_config.strVersionNo
    cboMisc1.SelLength = 0
    cboMisc1.SelStart = 0
   
    m_bolchanged = False
    Exit Sub
Load_Fields_Err:
        CentralErrorHandler "frmSysConfig.Load_Fields"
        Resume Next
End Sub
what happens if you create a new form with just cboMisc and populate them in the same way... can you provide a trimmed down version that I can just paste into a .frm file and load... to see if it happens on mine aswell.
KOCUBA:

You need to clearly explain exactly what you mean by "highlighting".

You could mean the text in the combo box is highlighted (i.e. text of the current value is selected). However, you cannot mean this, because when the combo box looses focus, the text is displayed normally.

You could mean the item in the dropdown list is highlighted to match the text in the combobox.

Those are two possible meanings you could be referring to when you say "highlighting"

Please explain what you mean. Otherwise, everyone will be making suggestions based upon what they *think* you mean, which may not be the same.


-Dennis Borg
Avatar of KOCUBA

ASKER

smegghead,

I started a new project with one combo box and the following code.

Combo1.AddItem " ", 0
Combo1.AddItem "Test1", 1
Combo1.AddItem "Test2", 2
Combo1.AddItem "Test3", 3
Combo1.ListIndex = 1

And I still get the text in the combo box highlighted.

Dennis,

Again sorry for any confusion.  It is the text in the combo box that is highlighted.  I thought I helped clear that up in my second posting.  But maybe not.  I hope this helps a little more.

The really confusing thing is that it is more tha none combo box that is this way.  I could possibly see one but not six.

I dont know??
>It is the text in the combo box that is highlighted.

The reason I say this is not possible is because when the combo box looses the focus (i.e. you move the cursor to a different control, such as another combo box, a button, textbox, etc), the text in the combo box is no longer selected.

Given your original quote:

   When I display this form all of the
   data, in each of the boxes, in the
   form are highlighted.

Given the sample code you are using to populate the list box of you combo box, your very first item has one space.

Why are you adding an item that has nothing but spaces?

If you are trying to make the combo box have NO INITIAL VALUE, then you need to set the ListIndex property to -1:

   Combo1.AddItem "Test1", 1
   Combo1.AddItem "Test2", 2
   Combo1.AddItem "Test3", 3
   Combo1.ListIndex = -1

-Dennis Borg
Also remember, the items in your combo box is zero-based.

In other words, the first item is ListIndex = 0.

The second item is ListIndex=1.

And so on. So, if you want the FIRST ITEM to be the default value of the combo box, then you would set the ListIndex property to Zero (0), not 1:

   Combo1.AddItem "Test1", 1
   Combo1.AddItem "Test2", 2
   Combo1.AddItem "Test3", 3
   Combo1.ListIndex = 0 '<---- Set to FIRST item in the list

-Dennis Borg
Avatar of KOCUBA

ASKER

Dennis,

That is why this is driving me completely nuts.  It is like all of those boxes are selected at the same time. ????

The addition of the space is so that if the user does not want any value in there it will blank it out in the database.


FYI... I took one of the combo boxes and did not load the items and it does not come back with the text selected. I put it back in and it goes back to what it was doing. ??
Avatar of KOCUBA

ASKER

Okay,

I shortened the problem down into another project file. And it is still doing the same thing.  Here is the code:

Option Explicit
Public connLite As ADODB.Connection     'Connection to the Oracle Lite database.
Public g_config As clsConfig
Dim MiscCode(9, 1) As String


Private Sub Form_Load()
Dim inti  As Integer
Set connLite = New ADODB.Connection
    connLite.IsolationLevel = adXactRepeatableRead
    connLite.Open "DSN=ol_mdbs;UID=mdbs;PWD=mdbs;"
Set g_config = New clsConfig
    g_config.db_Start connLite
    Load_MiscCodes
   
 inti = 0
    While MiscCode(inti, 0) <> ""
        cboMisc1.AddItem MiscCode(inti, 1)
        'cboMisc2.AddItem MiscCode(inti, 1)
        'cboMisc3.AddItem MiscCode(inti, 1)
        'cboMisc4.AddItem MiscCode(inti, 1)
        inti = inti + 1
    Wend
    If g_config.strMiscType1 <> "" Then
        inti = 0
        While MiscCode(inti, 0) <> g_config.strMiscType1
            inti = inti + 1
        Wend
        cboMisc1.Text = MiscCode(inti, 1)
    End If
    'txtMisc1.Text = g_config.strMiscValue1
    inti = 0
    Text1.Text = "Wow"
   
End Sub
Public Sub Load_MiscCodes()
Dim inti As Integer
Dim rsCodes As ADODB.Recordset
Set rsCodes = New ADODB.Recordset
rsCodes.Open "Select misccode,description from MDBS.CUSTINFO", connLite, adOpenDynamic, adLockOptimistic

inti = 1
MiscCode(0, 0) = " "
MiscCode(0, 1) = " "
While Not rsCodes.EOF
    MiscCode(inti, 0) = rsCodes.Fields!MiscCode
    MiscCode(inti, 1) = rsCodes.Fields!Description
    inti = inti + 1
    rsCodes.MoveNext
Wend
If rsCodes.State <> adStateClosed Then
    rsCodes.Close
End If
Set rsCodes = Nothing

End Sub


Anyone having any ideas???
>That is why this is driving me completely nuts.  It is like all of those
>boxes are selected at the same time. ????

Are you saying that *ALL* your combo boxes, even when they do *NOT* have the focus and when their drop-down list is *NOT* dropped down, that the text displayed in the TextBox portion of the control is highlighted, as if the I-Beam cursor was in the control and you selected all the text?

-Dennis Borg
Avatar of KOCUBA

ASKER

Dennis,

This is absoutely correct.  One of the text boxes actually has the cursor blinking in it and ALL of the combo boxes have the corresponding text highlighted.

Weird huh??
Given you understand what I'm referring to:

Then you have a problem that is not related to how you wrote your program. Rather, you have an issue where you need to reinstall Visual Basic.

There are several controls which have a property named HideSelection. When this property is set to True, the selected text is hidden when the control looses focus (and the text is displayed normally). But when set to False, the text is still displayed in its highlighted form. An example of this is the ListView control.

However, the standard combo box control which ships with VB does not have this property.

-Dennis Borg
The standard combo box automatically hides the selected text (thus displaying the text normally) when it looses the focus.

-Dennis Borg
Try this:

Private Sub Combo1_GotFocus()
    Combo1.SelStart = 0
End Sub
Gorank..

if you read the above comments, you'll see that I've already suggested that. And it didn't work

My comment was posted on : Monday, October 23 2000 - 02:37PM BST

Also, you should always make suggestions as 'comments' rather than 'answers' (unless you are positive this is the correct response) as this locks the question.
Avatar of KOCUBA

ASKER

GoranK,

As smeggshead said that did not work.

In reviewing this form, with people who make the decisions, it has been decided to switch them to Dropdown list.  This way nothing can be entered into that box besides what is in the list. Obviously!! I know you all knew that but kept on typing aways.
Well oddly enough when I switched them all to 2- Dropdown List.  the problem ceased.  No clue why, it just isn't happening on this style.  I haven't changed anything else.  So since smegghead mentioned about the style I should probably give the points to him.

Thank You all for all the help given to me.
Dave
IT WORKS!!!!!

I've checked again, and it works...

I'm using

Style : 0 - Dropdown Combo

And question was:

I have a number of combo  boxes on a form.  When I display this form all of the data, in each of the boxes, in the form are highlighted.  How can I get this not to happen?  it is really starting to irratate me.

For this question, my answer works!!!

I've tested this with 2 combos and it worked. That means, when you show your page with all your combos, nothing would be highlighted...
GoranK:

Somehow, I strongly suspect that you were not experiencing the same phenomona (sp?) which KOCUBA was experiencing:

   Having several combo boxes on a form, all of which shows Highlighted Text, even when they do not have the focus.

Are you honestly telling us that you have 2 combo boxes on your form, and *BOTH* AT THE SAME TIME are showing Highlighted Text?!! And that when Combo1 receives the focus, your code (Combo1.SelStart=0) causes *BOTH* combo boxes to display the text in non-highlighted form?


-Dennis Borg
Avatar of KOCUBA

ASKER

Yes,
I'm glad it worked for you.  But for some reason for me it did not work.

For me switching to the dropdown list worked and it goes in the direction that they want the application to go.

So sorry but I can not award you the points.
I've only just recieved email notification of this question's activity... this is becoming a nightmare.

Glad you got it working.... I don't think I've ever used a combobox with a style other than dropdown list (probably just my preference though)

Smeeeeeg.
Avatar of Asta Cu
Greetings.
 
This question is still open today, perhaps it was overlooked or just lost in the volumes.  Please return to this question to update it with comments if more information is needed to get your solution.  If you've been helped by the participating expert(s), you may just convert their comment to the accepted answer and then grade and close.  This benefits others who then search our PAQ for just this solution.  A win/win scenario.
 
If you wish to pay multiple participants, you can do so by creating a zero point question in the Community Support topic area, include this link and tell them which experts you'd like to pay what amounts.  If you'd like to delete this question, use the same process as above, but explain why you think it should be deleted.  Here is the Community Support link:   https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
You can always click on your profile to see all your open questions, in the event you also have other open items to be resolved.   If your number of Questions Asked is not equal to the number of Answers Graded, choose to VIEW question history, and you'll quickly be able to navigate to your open items to close them as well.

I've had excellent help from experts-exchange through the years and find the real key to getting what I need is to remain active in all my questions, responding with results to suggestions until my solution is found, and recommend that highly.
 
Thank you very much for your responsiveness, it is very much appreciated.  
":0)  Asta
 
P.S.  Some of the older questions from last year are not in the proper comment date order, and Engineering has been advised.  
ASKER CERTIFIED SOLUTION
Avatar of costello
costello

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I ran into the problem of populating several combo boxes on a form and having them all show up highlighted - just like the problem described here. While turning them all into the DropDownList style eliminates the highlighting problem - that's not a great solution because that's not the style desired for the control.  I have found a trick that works.

While you are constructing and populating the combbox set it to the DropDownList style. Then override the OnEnter method of the ComboBox and if you want a different style set your DropDownStyle there before called base.OnEnter().  Works like a charm.