?
Solved

Combobox: How to set the position to desired index

Posted on 2005-03-21
8
Medium Priority
?
285 Views
Last Modified: 2010-05-02
Hi all,

I have a handle to combox box(this is from external application- App A).

Now I want to set the value to desired position using my application(App - B)

How can I do this??

Thanks
Sudhakar
0
Comment
Question by:sudhakar_koundinya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 13589613
I have found this method

Private  Declare Function DlgDirSelectComboBoxEx Lib "user32" Alias "DlgDirSelectComboBoxExA" (ByVal hWndDlg As Long, ByVal lpszPath As String, ByVal cbPath As Long, ByVal idComboBox As Long) As Long
But facing problem

Could you please help me??

Thanks
sudhakar



0
 
LVL 5

Expert Comment

by:Rubyn
ID: 13590087
Tell me, to select an item in it, you have the position number or text.
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 13590109
Text is preferred
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:Rubyn
ID: 13590140
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 Const CB_SELECTSTRING = &H14D

Private Sub Command1_Click()
Dim hCombo As Long
    Let hCombo = Combo1.hwnd
    If SendMessage(hCombo, CB_SELECTSTRING, -1, ByVal "World") = 0 Then
        MsgBox "Not Found"
    End If
End Sub

Private Sub Form_Load()
    Call Combo1.AddItem("Hello")
    Call Combo1.AddItem("World")
    Call Combo1.AddItem("Rubyn")
End Sub

Put one Combo and Command on a form and paste the code
Want any help inform me :)
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 13590173
Ok thanks,
 It seems I am facing some problem with text selection. May I have an exampple based on index??

If that works, I will change my logic accoringly

Thanks
Sudhakar
0
 
LVL 5

Accepted Solution

by:
Rubyn earned 1000 total points
ID: 13590209
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 Const CB_SELECTSTRING = &H14D
Private Const CB_SETCURSEL = &H14E

Private Sub Command1_Click()
Dim hCombo As Long
    Let hCombo = Combo1.hwnd
    '-1 for null select, 0 for 1st item and so on
    If SendMessage(hCombo, CB_SETCURSEL, 1, 0) = 0 Then
        MsgBox "Not Found"
    End If
End Sub

Private Sub Form_Load()
    Call Combo1.AddItem("Hello")
    Call Combo1.AddItem("World")
    Call Combo1.AddItem("Rubyn")
End Sub
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 13590236
Great Help. :-)
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 13590259
Actually I am working with Office Outlook 2003  project. And I am facing some problems

So, in order to resolve these problems, I need to use Win API's Message Sending procedures.
As of now I have tested this with MFC- VB Communication.

When I am at work place,  will test the same with 2003. If I get any problems, I will post new queries here. And I hope you will be there to help me.

Thanks Again


Regards
Sudhakar






0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question