I have been searching for days all over the web, including this place for the answer to my question - all to no avail. At first I hesitated to ask here because last time I asked a question I got severely beaten for not asking it properly. So I'll try again. Here's the scenario:
I have built a Windows desktop application for our company to track customer orders. It uses a MySQL database hosted on my own server. It is fairly simple and it's working fine. My application has several different data bound controls and all is well. Really, it works just great.
There is a datagridview which displays all the orders a particular customer has placed. When the user clicks on the Order Number column in one of the rows a query is run which returns data specific to that order. One piece of data returned is the status of that order.
But I want to access that one piece of data WITHOUT using a data bound control - in this case it's a text box bound to one of the fields in a table in my database. I hide that control because it shows some rather cryptic data. That piece of data is a status code for the orders in the table. These codes are not self-apparent - they mean nothing unless you know what they refer to. You can see this in the code snippet below. I would rather not have this hidden text box on the form. I would rather obtain the value programmatically but I cannot for the life of me find the proper way to do this.
My code snippet:
private void getCustData2DataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
string ordnum = null;
string statusCode = null;
if (e.RowIndex >= 0)
{
DataGridViewRow row = getCustData2DataGridView.Rows[e.RowIndex];
ordnum = row.Cells[0].Value.ToString();
}
try
{
this.ecom_ordersTableAdapter.Fill(this.rBTCO_DBDataSet1.ecom_orders, ordnum);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
statusCode = statusdata.Text; //gets the value from the hidden textbox which is bound to the "status" field in the ecom_orders table.
switch (statusCode)
{
case "NS":
label5.Text = "Processing";
label5.ForeColor = Color.Green;
break;
case "P":
label5.Text = "Pending Payment";
label5.ForeColor = Color.Blue;
break;
case "X":
label5.Text = "Cancelled";
label5.ForeColor = Color.Red;
break;
case "C":
label5.Text = "Completed";
label5.ForeColor = Color.Blue;
break;
default:
label5.Text = null
label5.ForeColor = Color.Black;
break;
}
}
The status codes reside in the rbtcoDataSet1.ecom_orders table.
You can see in the switch
block where I assign strings to the different status codes so they have meaning to the user. Since all the database manipulation in this application has been generated by Visual Studio I really don't have a clue as how to get this one piece of data without using a bound control. Can it even be done in this case?
Let the beatings commence. Please be gentle!