0

I added items using Properties and at runtime, the dropdown had no items there.

String Collection Editor

I am a little confused and would really appreciate any help.

I also didnt see a way for me to assign an Event Handler to the Combobox.

software is fun
  • 7,286
  • 18
  • 71
  • 129
  • What do you think you need to do in the events - the control will automatically save the selected text to the underlying datasource. As I explained before, if you are going to create the columns manually, you need to tell it how the columns map to the datasource using DataPropertyName. – Ňɏssa Pøngjǣrdenlarp Aug 15 '16 at 17:32
  • Well the values for the items in the combobox are "hard coded" and not derived from a data source. however when i click on "Completed". I want to run an UPDATE query to update the record in the database – software is fun Aug 15 '16 at 17:35
  • [This answer](http://stackoverflow.com/a/38922735/1070452) uses values "hard coded" as a datasource - they are not mutually exclusive. You are over thinking it - when the user makes a change, the data table will make note of the change, All you have to do is update using the dataadptaer – Ňɏssa Pøngjǣrdenlarp Aug 15 '16 at 17:39
  • To add an eventhandler to the combobox you need to catch it when it is overlaid to the DGV in the EditControlShowing event. It is in the e.Control parameter and you can store it in a variable (recommended) and add handlers to all the usual events.. Note that they are rather icky at releasing the new value to the cell until the cell is left! - Note that you hardly ever need to do this! – TaW Aug 15 '16 at 17:43
  • 1
    Note also that you will get errors populating the control if that *exact text* is not what it stored in the db. You never disclosed the SQL query, so your never ending problem might start there. – Ňɏssa Pøngjǣrdenlarp Aug 15 '16 at 17:49
  • the SQL query that is being run has nothing to do with the Items in my Combobox not appearing. However if you really need to know its UPDATE SignIn SET Complete=Yes WHERE SignInID= (row selected's ID #) – software is fun Aug 15 '16 at 17:53
  • If there is no actual column in the DB for that text and it just equates to a bool Completed column, why not use a checkbox. Let the user mark them, then `myDA.Update(myDataTable)` will update 1 or 1 million rows as needed. It is also possible to map that text to a Yes/No value if a DropDown is essential – Ňɏssa Pøngjǣrdenlarp Aug 15 '16 at 18:13
  • If they select "Change Reason", we pop up a UI that allows them to change the reason for the visitors visit. – software is fun Aug 15 '16 at 19:01

1 Answers1

0

use combobox.Items.Add() to add items to the combo box, then you can set the default selection using combobox.SelectedIndex

more info: https://msdn.microsoft.com/en-us/library/aa983551(v=vs.71).aspx

Example:

foreach (string s in SerialPort.GetPortNames())
{
    comboMachinePort.Items.Add(s);
}
comboMachinePort.SelectedIndex = 0;
Xander Luciano
  • 3,753
  • 7
  • 32
  • 53