Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21238

Combo box Shadow problem

$
0
0
Hi,

I am using Visual Basic 6 on Windows XP test machine.

Here is what I have :

Option Explicit

Private Const CB_FINDSTRING = &H14C

Private Const CB_SHOWDROPDOWN = &H14F

Private Const LB_FINDSTRING = &H18F

Private Const CB_ERR = (-1)

Dim cn As New ADODB.Connection

Dim rs As New ADODB.Recordset

Dim constr As String

Dim sql As String

Private Declare Function SendMessage Lib _

"user32" Alias "SendMessageA" (ByVal _

hWnd As Long, ByVal wMsg As Long, _

ByVal wParam As Long, lParam As Any) _

As Long

Private Sub Form_Load()

constr = "Provider=OraOLEDB.Oracle;Data Source=orcl;User ID=scott;Password=tiger;"

End Sub



Private Sub Combo1_GotFocus()

SendMessage Combo1.hWnd, CB_SHOWDROPDOWN, 1, ByVal 0&

End Sub



Private Sub Combo1_KeyPress(KeyAscii As Integer)

Dim CB As Long

Dim FindString As String

If KeyAscii < 32 Or KeyAscii > 127 Then Exit Sub

If Combo1.SelLength = 0 Then

FindString = Combo1.Text & Chr$(KeyAscii)

Else

FindString = Left$(Combo1.Text, Combo1.SelStart) & Chr$(KeyAscii)

End If

sql = "select distinct object_name from dba_objects where upper(object_name) like '" & UCase(FindString) & "%'"

cn.Open constr

rs.Open sql, cn, adOpenForwardOnly, adLockPessimistic, adCmdText



With Combo1

.Clear

Do While Not rs.EOF

.AddItem rs.Fields("OBJECT_NAME").Value

rs.MoveNext

Loop

End With

rs.Close

cn.Close



SendMessage Combo1.hWnd, CB_SHOWDROPDOWN, 1, ByVal 0&



CB = SendMessage(Combo1.hWnd, CB_FINDSTRING, -1, ByVal FindString)



If CB <> CB_ERR Then

Combo1.ListIndex = CB

Combo1.SelStart = Len(FindString)

Combo1.SelLength = Len(Combo1.Text) - Combo1.SelStart

End If



KeyAscii = 0

End Sub

Private Sub Form_Paint()

SendMessage Combo1.hWnd, CB_SHOWDROPDOWN, 0, ByVal 0& 'To CloseDropDown Combo

'I need this because otherwise at the start up of form shadow of combo box appears!

End Sub

Everything works fine except one issue. Whenever items in combo box becomes lesser than earlier one, then on the form I sees the shadow (white portion) of the combo box i.e. suppose user is typing in the combo box, it is populated as the values in the table and at the first typing there are 100 rows, as and when user types more there is white shadow and boundry of combo box looks ugly and incomplete.

Kindly tell me how do I correct this.

This is how combo box looks like :
Name:  cmb1.JPG
Views: 23
Size:  16.5 KB
This is after pressing enter key :
Name:  cmb2.JPG
Views: 23
Size:  12.2 KB

This is my first post on the forum, so bear with me, if I am missing something important.

Regards

Girish Sharma
Attached Images
  

Viewing all articles
Browse latest Browse all 21238

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>