Thursday, July 29, 2004

I am bored. The entire company is on an outing, and here I site with no desire to do anything. I would leave but the phone switch broke this morning, so I have to stay around while this technician tries to figure out what is wrong with it. If I could just think of somewhere to go on the Internet, or get the /whatever/ together so I will actually do some work. I am going to be stuck here all day, I can see it now. It's already 12:11 and there's no end in site.

Thursday, July 22, 2004

I am having some trouble with setting a value to ComboBox.SelectedValue and then saving that value using DataBinding.
Example:
// There are five controls on a form, 1 ComboBox (comboBox), 2 TextBoxes (tbx1, tbx2) and 2 buttons (btnNew, btnSave)
DataSet dsFillCombo;
DataSet ds1;
// I fill each DataSet using separate data adapters
// The Combo is Bound like this
comboBox.DataSource = dsFillCombo;
comboBox.DisplayMember = "sectionIds.sectionName";
comboBox.ValueMember = "sectionIds.sectionId";
// So far, pretty basic. Now I bind the controls on the form to my other DataSet
tbx1.DataBinding.Add("Text", ds1, "users.fName");
tbx2.DataBinding.Add("Text", ds1, "users.lName");
comboBox.DataBinding.Add("SelectedValue", ds1, "users.sectionId");
BindingManagerBase bm = BindingContext[ds1, "users"];

// Still pretty basic, I could add more buttons to change the record position, and the values
// would in the form controls would change with the data rows.
// Now for my issue!
// For the btnNew I want to add a new record to the dataset and set the comboBox to the same
// value that it is currently.
private void btnNew_Click(object sender, System.EventArgs e)
{
int i = Convert.ToInt32(this.comboBox.SelectedValue);
bm.AddNew();
this.comboBox.SelectedValue = sid;
}
// Now I click the Save button and...
private void btnSave_Click(object sender, System.EventArgs e)
{
bm.EndCurrentEdit();
}

As soon as I do that an Exception is thrown:
System.NoNullAllowedException: Column 'sectionId' does not allow nulls. ...

If I actually select a new value using the comboBox then the new record is saved without an issue.

Is there a way to set the SelectedValue of a ComboBox from code and have that value recongnized by DataBinding?

Thank you for any assistence.

--------------------------------
From: Brett SlaskiClass [Discussions]: "databinding"

Tuesday, July 06, 2004

Singltons baby...
Implementing Singleton in C#

Thursday, July 01, 2004

Simple databinding to a UserControl in C# has been quite a challenge. Here is one referrence to keep on hand.
Google Search: bind property of usercontrol C#