OK, so this is my dilemma. I have a window form that will be used to support an SQL table. The SQL table has foreign keys pointing to code tables. I use BindingNavigator and BindingSource to display the contents of this table one row at a time in the form using text fields, comboboxes, and datepickers. The form displays the table key field, the BindingNavigator, and one of the main fields of the table called the “Short Description” in the group box at the top of the screen. The purpose of this group is to allow the user to enter an identification number or select an item from the list with a list for viewing / editing. (It is not possible to send images because I am a new user).
I was able to display the data displayed on the form, depending on the navigation of the BindingNavigator, i.e. Back, fwd, etc. But I can’t get a form to display the relevant data when I select an item from the "Short Description" drop-down list. This should be due to the binding of my controls. It is possible that I have an Oneway binding to a BindingSource, not a TwoWay binding, but I cannot figure out how to do this with a TwoWay binding.
Here is the code that sets up the form that runs in the FormLoad event:
private void SoftwareRequestMaint_Load(object sender, EventArgs e)
{
try
{
conn.Open();
string sqlQuery = "SELECT * FROM Requests ORDER BY BriefDesc; " +
"SELECT combined = Description + ' [' + convert(varchar,Priority_ID) + ']', Priority_ID FROM Priority ORDER BY combined; " +
"SELECT combined = Description + ' [' + convert(varchar,Category_ID) + ']', Category_ID FROM Category ORDER BY combined; " +
"SELECT combined = Givname + ' ' + Surname, User_ID FROM Users ORDER BY combined; " +
"SELECT combined = Description + ' [' + convert(varchar,System_ID) + ']', System_ID FROM System ORDER BY combined";
da.SelectCommand = new SqlCommand(sqlQuery, conn);
da.TableMappings.Add("Table", "Requests");
da.TableMappings.Add("Table1", "Priority");
da.TableMappings.Add("Table2", "Category");
da.TableMappings.Add("Table3", "Users");
da.TableMappings.Add("Table4", "System");
da.Fill(ds);
DataColumn colParent =
ds.Tables["Requests"].Columns["Priority"];
DataColumn colChild =
ds.Tables["Priority"].Columns["Priority_ID"];
DataRelation RequestsPriority =
new DataRelation("RequestsPriority", colParent, colChild, false);
ds.Relations.Add(RequestsPriority);
bsRequests.DataSource = ds.Tables["Requests"];
bsRequests.Binding.Mode = BindingMode.TwoWay;
uxIDTxt.DataBindings.Add("Text", bsRequests, "Requests_ID");
uxMenuOptTxt.DataBindings.Add("Text", bsRequests, "MenuOpt");
uxProcessNameTxt.DataBindings.Add("Text", bsRequests, "ProcessName");
uxBriefDescCbo.DataSource = bsRequests;
uxBriefDescCbo.DisplayMember = "BriefDesc";
uxBriefDescCbo.ValueMember = "Requests_ID";
uxBriefDescCbo.DataBindings.Add("SelectedValue", bsRequests, "Requests_ID");
uxSystemCbo.DataSource = ds.Tables["System"];
uxSystemCbo.DisplayMember = "combined";
uxSystemCbo.ValueMember = "System_ID";
uxSystemCbo.DataBindings.Add("SelectedValue", bsRequests, "System");
uxPriorityCbo.DataSource = ds.Tables["Priority"];
uxPriorityCbo.DisplayMember = "combined";
uxPriorityCbo.ValueMember = "Priority_ID";
uxPriorityCbo.DataBindings.Add("SelectedValue", bsRequests, "Priority");
uxCategoryCbo.DataSource = ds.Tables["Category"];
uxCategoryCbo.DisplayMember = "combined";
uxCategoryCbo.ValueMember = "Category_ID";
uxCategoryCbo.DataBindings.Add("SelectedValue", bsRequests, "Category");
uxRequestedByCbo.DataSource = ds.Tables["Users"];
uxRequestedByCbo.DisplayMember = "combined";
uxRequestedByCbo.ValueMember = "User_ID";
uxRequestedByCbo.DataBindings.Add("SelectedValue", bsRequests, "RequestedBy");
uxAssignedToCbo.DataSource = ds.Tables["Users"];
uxAssignedToCbo.DisplayMember = "combined";
uxAssignedToCbo.ValueMember = "User_ID";
uxAssignedToCbo.DataBindings.Add("SelectedValue", bsRequests, "AssignedTo");
uxSignedOffByCbo.DataSource = ds.Tables["Users"];
uxSignedOffByCbo.DisplayMember = "combined";
uxSignedOffByCbo.ValueMember = "User_ID";
uxSignedOffByCbo.DataBindings.Add("SelectedValue", bsRequests, "SignedOffBy");
uxRequestDetailsRtb.DataBindings.Add("Text", bsRequests, "Details");
uxItemsChangedRtb.DataBindings.Add("Text", bsRequests, "ItemsChanged");
uxInstallationInstructionsRtb.DataBindings.Add("Text", bsRequests, "InstallInstr");
}
catch (Exception excp)
{
SAPSCommon.Instance.ShowErrorMsg(excp.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
}
dirtyData = false;
}
BTW The streams are unsorted, i.e. their Sorted property is set to False. Sorting is performed as part of the SQL SELECT statements.
What am I doing wrong? Any ideas?
Regards, Walter