'What is preventing Combobox SelectedValue from setting?
I have several comboboxes, all similar code and only one, CustomerSelector.SelectedValue, is not working. I have even tried setting the value like this: CustomerSelector.SelectedValue=32
.
This Method is for loading all the Project info to the form and is called in the form Load event. The data seems to load fine, I have even loaded 'id' to the DisplayMember to verify.
Any ideas what is preventing SelectedValue from setting?
void loadProjectInfo()
{
if (isProjectInfoLoaded == false)
{
try
{
DataTable dt4 = new DataTable();
DBConnector db4 = new DBConnector();
db4.query = "SELECT * FROM s1_pm_project WHERE id=" + JobID;
dt4 = db4.getDataTable();
DataRow PMProject = dt4.Rows[0];
ProjectNameTextbox.Text = PMProject["ProjectName"].ToString();
this.Text = ProjectNameTextbox.Text;
ProjectAddressTextbox.Text = PMProject["Address"].ToString();
ProjectAddressCity.Text = PMProject["City"].ToString();
ProjectAddressState.DataSource = USStates.States();
ProjectAddressState.ValueMember = "Abbreviations";
ProjectAddressState.DisplayMember = "Abbreviations";
ProjectAddressState.SelectedIndex = -1;
if (!Convert.IsDBNull(PMProject["State"]))
ProjectAddressState.SelectedValue = PMProject["State"].ToString();
ProjectAddressPostalCode.Value = (!Convert.IsDBNull(PMProject["ZipCode"])) ? Convert.ToInt32(PMProject["ZipCode"]) : 00000;
DBConnector db5 = new DBConnector();
db5.query = "SELECT id, Name FROM s1_customer ORDER BY Name ASC";
CustomerSelector.DisplayMember = "Name";
CustomerSelector.ValueMember = "id";
CustomerSelector.DataSource = db5.getDataTable();
CustomerSelector.SelectedIndex = -1;
//if (!Convert.IsDBNull(PMProject["CustomerID"]))
// CustomerSelector.SelectedValue = Convert.ToInt32(PMProject["CustomerID"]);
CustomerSelector.SelectedValue=32;
DBConnector db1 = new DBConnector();
db1.query = "SELECT id, description FROM s1_app_status WHERE id < 2";
ProjectInfo_Status.DataSource = db1.getDataTable();
ProjectInfo_Status.DisplayMember = "description";
ProjectInfo_Status.ValueMember = "id";
ProjectInfo_Status.SelectedValue = Convert.ToInt32(PMProject["IsActive"]);
DBConnector db2 = new DBConnector();
db2.query = "SELECT id, description FROM s1_pm_roll";
ProjectInfoRollSelector.DataSource = db2.getDataTable();
ProjectInfoRollSelector.ValueMember = "id";
ProjectInfoRollSelector.DisplayMember = "description";
ProjectInfoRollSelector.SelectedIndex = -1;
if (Convert.ToInt32(PMProject["RollID"]) > 0)
ProjectInfoRollSelector.SelectedValue = Convert.ToInt32(PMProject["RollID"]);
DBConnector db3 = new DBConnector();
db3.query = "SELECT id, fullname FROM s1_user WHERE id>1";
ProjectInfoPMSelector.DataSource = db3.getDataTable();
ProjectInfoPMSelector.ValueMember = "id";
ProjectInfoPMSelector.DisplayMember = "fullname";
ProjectInfoPMSelector.SelectedIndex = -1;
if (Convert.ToInt32(PMProject["PMID"]) > 0)
ProjectInfoPMSelector.SelectedValue = Convert.ToInt32(PMProject["PMID"]);
ProjectInfoJobNoTextbox.Text = PMProject["JobNo"].ToString();
ProjectInfoValueTextbox.Value = Convert.ToDecimal(PMProject["ApproxValue"]);
if (!Convert.IsDBNull(PMProject["StartDate"]))
StartDateSelector.Value = Convert.ToDateTime(PMProject["StartDate"]);
if (!Convert.IsDBNull(PMProject["ProjectedEndDate"]))
ProjectedEndDateSelector.Value = Convert.ToDateTime(PMProject["ProjectedEndDate"]);
if (!Convert.IsDBNull(PMProject["EndDate"]))
EndDateSelector.Value = Convert.ToDateTime(PMProject["EndDate"]);
CustomerPOTextbox.Text = PMProject["CustomerPO"].ToString();
SalesTaxRateTextbox.Value = Convert.ToDecimal(PMProject["SalesTaxRate"]);
if (!Convert.IsDBNull(PMProject["WarrantyBegin"]))
WarrantyBegin.Value = Convert.ToDateTime(PMProject["WarrantyBegin"]);
if (!Convert.IsDBNull(PMProject["WarrantyEnd"]))
WarrantyEnd.Value = Convert.ToDateTime(PMProject["WarrantyEnd"]);
loadContactList();
}
catch (Exception ex)
{
Errors.Exception(ex);
}
isProjectInfoLoaded = true;
}
}
This is the output from SELECT id, Name FROM s1_customer ORDER BY Name ASC
:
id | Name |
---|---|
22 | 18-8 Sherman Oaks |
206 | Alejo Lugo |
233 | Americo Builders, LLC |
235 | AMS Solutions, Inc |
1 | ARRIS Builders, Inc. |
209 | Chris Thrower |
105 | CME Refrigeration Controls |
53 | Coastline Provisions |
117 | Cortech Construction, Inc |
6 | Development Support Services, Inc. |
146 | East Bay Restaurant Supply Inc |
31 | Fitness Mania |
7 | Fulcrum Construction |
32 | Hardesty & Associates, Inc. |
135 | Howards Appliances, Inc. |
9 | J Ray Construction |
10 | J&L Metal Products |
12 | Jahanna L. Nichols Interior Design, Inc |
69 | James Barb Construction, Inc |
61 | JRE Construction, Inc. |
13 | Kamran and Company, Inc. |
15 | LA Deli Distributors, Inc. |
98 | Lovisa America, LLC |
40 | Mobile Customer |
120 | N CORONA |
180 | N SANTA CLARA |
5 | N SERVICE SALE |
129 | Orangecrest Properties LLC |
223 | Other Customer |
78 | Pacific Westline, Inc. |
Output from SELECT * FROM s1_pm_project WHERE id=
:
id | ProjectName | IsActive | CustomerID | RollID | PMID | JobNo | ApproxValue | StartDate | EndDate | ProjectedEndDate | CustomerPO | SalesTaxRate | EstimateID | WarrantyBegin | WarrantyEnd |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
141 | Gorjana - Carlsbad | 1 | 32 | 1 | 23 | 22199 | 37000.00 | 2022-02-07 | 2022-04-29 | 2022-04-29 | 22-012-23 | 0.00 | NULL | 2022-04-29 | 2023-04-29 |
Solution 1:[1]
The problem ended up being with the database, specifically the id
field of s1_customer
. For some reason it had the 'unsigned' attribute. When that was removed, everything worked as expected.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mike |