Not sure if the title accuratly reflects the question, but here it goes.

I have a dropdown (a ComboBox) with some text. Simple enough, when the dropdown is opened and text selected, it puts the text in a text box below.

        If cbCallNotesPrefills.Text = "Sample Text" Then
            txtCallNotes.Text = "Sample Text"
        End If

I made it that instead of hard coding the text in the dropdown, it's picking it up from a text file. The reason was so an end user can have their own "Sample text" or whatever they want in the dropdown.

So if thats the case, I can't hard code it anymore like the sample above. They might change it to something else.

Question is, how tough is it to have this dynamic text be sent to the textbox? I'm trying to find some samples, not having much luck.

I thought about this-

        If cbCallNotesPrefills.text = "Sample Text" Then
            txtCallNotes.Text = cbCallNotesPrefills.SelectedValue.ToString
        End If

But nope, I'm not even close. How do I deal with that "Sample text"?

Hello Mistah Taylor. I'm not sure I understand. Do you want the string "Sample Text" to appear in the combo box and when the user selects it, text from a file gets copied to the textbox? Or do you want text from the file to be loaded into the combo box (instead of "Sample Text") and have that text copied to the textbox? In either case, you have to have the filename specified somewhere. Either way it is not complicated.

If you just want to copy the selected text then do

txtCallNotes.Text = cbCallNotesPrefills.Text

Just be a little more specific and I'll throw some code at you.

I posted too soon. I think I figured it out.

 Private Sub cbCallNotesPrefills_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbCallNotesPrefills.SelectedIndexChanged

        AppendtxtCallNotesText()
        txtCallNotes.Text = cbCallNotesPrefills.Text

    End Sub

    Private Sub AppendtxtCallNotesText()
        If txtCallNotes.Text = "" Then
            Return
        Else
            txtCallNotes.AppendText(cbCallNotesPrefills.SelectedValue)
        End If
    End Sub

Only when I select a new value, I get

Object reference not set to an instance of an object.

On

txtCallNotes.AppendText(cbCallNotesPrefills.SelectedValue)

I'm not sure why you do

AppendtxtCallNotesText()

when the next statement just undoes what you just did. Why not just do

Private Sub cbCallNotesPrefills_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbCallNotesPrefills.SelectedIndexChanged

    txtCallNotes.Text = cbCallNotesPrefills.Text

End Sub

D-oh... Again, I'm overthinking and overcomplicating things. Typical me.

Thanks Jim.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.