User Input – pick list
I know how to get a prompt for user input when a map runs – asking for a batch ID for example. But is there a way to get user input where the user chooses from a list of possible values obtained by querying a SQL table. For example, choose a customer from this pick list of customers in the SQL customers table. I am working on a cash integration where users have to type in a Checkbook ID, and I'm afraid they're going to make mistakes typing it. The list is fairly short, so I would rather have them just select it from a pick list. Thanks in advance!
Answers
Best Answer
Sherry,
You basically have to create a form and add the ComboBox control to that form. Here is a sample of the code. I didn't write the code to go get data from a SQL table but that would be standard ADO.NET code that you would write to loop through the data set and add items to the combobox. I hope this helps.
' loop through data and add items to the combobox
'return the data
You basically have to create a form and add the ComboBox control to that form. Here is a sample of the code. I didn't write the code to go get data from a SQL table but that would be standard ADO.NET code that you would write to loop through the data set and add items to the combobox. I hope this helps.
Dim mapInterface As Integer = 1
'—————————————————————————————
Try
Dim dropdown as new System.Windows.Forms.ComboBox
' get data using ADO.NET
' loop through data and add items to the combobox
dropdown.Items.Add("My List Item")
dropdown.Items.Add("My second item")
'Create a new form
Dim form As New Form
'Set the form name
form.Text = "Select an Item"
'Add the text box and anchor it to each side of the form so it resizes with it
form.Controls.Add(dropdown)
form.Controls(0).Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right
'Use the ShowDialog() method instead of just Show() so the form persists until the user closes it
form.ShowDialog()
'return the data
dim txt as string
txt = (CType(form.controls(0), ComboBox)).SelectedText
Catch ex As Exception
If (mapInterface = 1) Then
Messagebox.Show(ex.Message, "DisplayAccounts Script Error")
End If
Return False
End Try
There is no way to create the form in SmartConnect is there? YOu mean create it in VB or C#?
Don
Don,
The problem with creating a form is that the Drawing namespace is not available and therefore you cannot place controls at specific spots on the form.
I will enter a problem report to see if we can get that namespace included.
Lorren
The problem with creating a form is that the Drawing namespace is not available and therefore you cannot place controls at specific spots on the form.
I will enter a problem report to see if we can get that namespace included.
Lorren
Greetings – I know this is REALLY old in geek years but …
I am interested in doing something similar – where does this code actually go?
thanks
John
I am interested in doing something similar – where does this code actually go?
thanks
John
John,
This code is actually a pre-map Script Task within the SmartConnect map.
Lorren
I have this code mostly working, but I’m not sure it’s actually capturing the selected value. Below is my code. When I run the map, it gives me a drop down box, and I can select ALL, By Customer, or By Parent. It defaults to ALL.
But my only option is to close the form; I don’t have an OK box. When the code gets to the message boxes so I can see what value has been captured, both boxes are blank. So the drop down box seems to be working, but it’s not capturing the value I select? Any additional help? Thanks.
Dim mapInterface As Integer = 1
‘—————————————————————————————
Try
Dim dropdown as new System.Windows.Forms.ComboBox
‘ get data using ADO.NET
‘ loop through data and add items to the combobox
dropdown.SelectedText = “ALL”
dropdown.Items.Add(“ALL”)
dropdown.Items.Add(“BY CUSTOMER”)
dropdown.Items.Add(“BY PARENT”)
‘Create a new form
Dim form As New Form
‘Set the form name
form.Text = “Choose Record Selection Method”
‘Add the text box and anchor it to each side of the form so it resizes with it
form.Controls.Add(dropdown)
form.Controls(0).Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right
‘Use the ShowDialog() method instead of just Show() so the form persists until the user closes it
form.ShowDialog()
‘return the data
dim txt as string
txt = (CType(form.controls(0), ComboBox)).SelectedText
messagebox.show((CType(form.controls(0), ComboBox)).SelectedText,”SelectedText ComboBox Result”)
messagebox.show(txt,”TXT String”)
Catch ex As Exception
If (mapInterface = 1) Then
Messagebox.Show(ex.Message, “Record Select Script Error”)
End If
Return False
End Try
But my only option is to close the form; I don’t have an OK box. When the code gets to the message boxes so I can see what value has been captured, both boxes are blank. So the drop down box seems to be working, but it’s not capturing the value I select? Any additional help? Thanks.
Dim mapInterface As Integer = 1
‘—————————————————————————————
Try
Dim dropdown as new System.Windows.Forms.ComboBox
‘ get data using ADO.NET
‘ loop through data and add items to the combobox
dropdown.SelectedText = “ALL”
dropdown.Items.Add(“ALL”)
dropdown.Items.Add(“BY CUSTOMER”)
dropdown.Items.Add(“BY PARENT”)
‘Create a new form
Dim form As New Form
‘Set the form name
form.Text = “Choose Record Selection Method”
‘Add the text box and anchor it to each side of the form so it resizes with it
form.Controls.Add(dropdown)
form.Controls(0).Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right
‘Use the ShowDialog() method instead of just Show() so the form persists until the user closes it
form.ShowDialog()
‘return the data
dim txt as string
txt = (CType(form.controls(0), ComboBox)).SelectedText
messagebox.show((CType(form.controls(0), ComboBox)).SelectedText,”SelectedText ComboBox Result”)
messagebox.show(txt,”TXT String”)
Catch ex As Exception
If (mapInterface = 1) Then
Messagebox.Show(ex.Message, “Record Select Script Error”)
End If
Return False
End Try
This little bit of code seems to be the issue.
dim txt as string
txt = (CType(form.controls(0), ComboBox)).SelectedText
I replaced it with this – same code, but it uses just ‘Text’ instead of ‘SelectedText’ Now the variable ‘txt’ has the value the user selects in the combo box.
dim txt as string
txt = (CType(form.controls(0), ComboBox)).Text
dim txt as string
txt = (CType(form.controls(0), ComboBox)).SelectedText
I replaced it with this – same code, but it uses just ‘Text’ instead of ‘SelectedText’ Now the variable ‘txt’ has the value the user selects in the combo box.
dim txt as string
txt = (CType(form.controls(0), ComboBox)).Text