Click here to Skip to main content
16,004,828 members
Home / Discussions / C#
   

C#

 
QuestionLoading combobox with items on form load Pin
Karlos_V3-Sep-07 23:35
Karlos_V3-Sep-07 23:35 
AnswerRe: Loading combobox with items on form load Pin
rah_sin3-Sep-07 23:43
professionalrah_sin3-Sep-07 23:43 
GeneralRe: Loading combobox with items on form load Pin
Karlos_V3-Sep-07 23:52
Karlos_V3-Sep-07 23:52 
AnswerRe: Loading combobox with items on form load Pin
originSH3-Sep-07 23:53
originSH3-Sep-07 23:53 
GeneralRe: Loading combobox with items on form load Pin
Karlos_V4-Sep-07 0:00
Karlos_V4-Sep-07 0:00 
GeneralRe: Loading combobox with items on form load Pin
originSH4-Sep-07 0:02
originSH4-Sep-07 0:02 
GeneralRe: Loading combobox with items on form load Pin
Karlos_V4-Sep-07 0:25
Karlos_V4-Sep-07 0:25 
GeneralRe: Loading combobox with items on form load Pin
originSH4-Sep-07 0:55
originSH4-Sep-07 0:55 
ahhhh dang it. In this case the method we're calling doesn't conform to the System.Delegate, which wants a void Method();.

Add this code to your class:

<br />
        private delegate void AddItemDelegate(object item);<br />
<br />
        private void AddComboBoxItem(object item)<br />
        {<br />
            cboComments.Items.Add(item);<br />
        }<br />


see how the delegate defines the method signature of the method?

private delegate "void AddItemDelegate(object item)"
private "void AddComboBoxItem(object item)"

And change your Invoke method call to:

<br />
cboComments.Invoke(new AddItemDelegate(AddComboBoxItem), item);<br />


this creates a new delegate of our specific definition, tells it to point at our 'AddComboBoxItem' method and passes item as a parameter.


The reason you have to use delegates and Invoke is that now you have said ... I want to use this method please, and the control will execute that method on the appropriate thread (i.e. the UI one), which prevents the cross threading issues.
AnswerRe: Loading combobox with items on form load Pin
Muammar©4-Sep-07 1:36
Muammar©4-Sep-07 1:36 
GeneralRe: Loading combobox with items on form load Pin
originSH4-Sep-07 1:43
originSH4-Sep-07 1:43 
GeneralRe: Loading combobox with items on form load Pin
Muammar©4-Sep-07 19:39
Muammar©4-Sep-07 19:39 
GeneralRe: Loading combobox with items on form load Pin
Skippums4-Sep-07 13:04
Skippums4-Sep-07 13:04 
GeneralRe: Loading combobox with items on form load Pin
Muammar©4-Sep-07 19:37
Muammar©4-Sep-07 19:37 
Questionhow to show tooltip for checked list box items on mouse move in c#? Pin
nicolus3-Sep-07 23:24
nicolus3-Sep-07 23:24 
QuestionUnable to clear textbox Pin
PartyGitsu3-Sep-07 23:17
PartyGitsu3-Sep-07 23:17 
AnswerRe: Unable to clear textbox Pin
DaveyM696-Sep-07 8:40
professionalDaveyM696-Sep-07 8:40 
GeneralRe: Unable to clear textbox Pin
PartyGitsu6-Sep-07 20:34
PartyGitsu6-Sep-07 20:34 
GeneralRe: Unable to clear textbox Pin
DaveyM697-Sep-07 0:57
professionalDaveyM697-Sep-07 0:57 
GeneralRe: Unable to clear textbox Pin
DaveyM697-Sep-07 1:20
professionalDaveyM697-Sep-07 1:20 
QuestionWCF Transport :confused: Pin
Cape Town Developer3-Sep-07 23:03
Cape Town Developer3-Sep-07 23:03 
AnswerRe: WCF Transport :confused: Pin
originSH3-Sep-07 23:06
originSH3-Sep-07 23:06 
GeneralRe: WCF Transport :confused: Pin
Cape Town Developer3-Sep-07 23:11
Cape Town Developer3-Sep-07 23:11 
QuestionConsole application run as a windows service or command line in C# 2.0 Pin
Sundarapandian.Balasubramanian3-Sep-07 22:50
Sundarapandian.Balasubramanian3-Sep-07 22:50 
AnswerRe: Console application run as a windows service or command line in C# 2.0 Pin
originSH3-Sep-07 22:57
originSH3-Sep-07 22:57 
GeneralRe: Console application run as a windows service or command line in C# 2.0 Pin
originSH3-Sep-07 22:59
originSH3-Sep-07 22:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.