Click here to Skip to main content
15,892,005 members
Home / Discussions / C#
   

C#

 
GeneralRe: Searching for opponents, what do I need? Pin
Link260022-Jul-04 16:45
Link260022-Jul-04 16:45 
GeneralRe: Searching for opponents, what do I need? Pin
Dave Kreskowiak22-Jul-04 16:53
mveDave Kreskowiak22-Jul-04 16:53 
GeneralRe: Searching for opponents, what do I need? Pin
Link260022-Jul-04 16:58
Link260022-Jul-04 16:58 
GeneralRe: Searching for opponents, what do I need? Pin
Colin Angus Mackay22-Jul-04 23:56
Colin Angus Mackay22-Jul-04 23:56 
GeneralRe: Searching for opponents, what do I need? Pin
Link260023-Jul-04 7:13
Link260023-Jul-04 7:13 
GeneralRe: Searching for opponents, what do I need? Pin
Bill Dean23-Jul-04 8:25
Bill Dean23-Jul-04 8:25 
GeneralRe: Searching for opponents, what do I need? Pin
Dave Kreskowiak23-Jul-04 10:40
mveDave Kreskowiak23-Jul-04 10:40 
GeneralReceiving NoNullAllowedException setting SelectedValue from code. Pin
Brett Slaski22-Jul-04 12:01
Brett Slaski22-Jul-04 12:01 
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
// 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 click btn_Save 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 assistance.



Brett Slaski
GeneralRe: Receiving NoNullAllowedException setting SelectedValue from code. Pin
Heath Stewart22-Jul-04 12:11
protectorHeath Stewart22-Jul-04 12:11 
GeneralRe: Receiving NoNullAllowedException setting SelectedValue from code. Pin
Brett Slaski23-Jul-04 9:30
Brett Slaski23-Jul-04 9:30 
GeneralRe: Receiving NoNullAllowedException setting SelectedValue from code. Pin
Heath Stewart23-Jul-04 10:00
protectorHeath Stewart23-Jul-04 10:00 
Generalnon-static class referencing Pin
Wolfman3222-Jul-04 12:00
Wolfman3222-Jul-04 12:00 
GeneralRe: non-static class referencing Pin
Heath Stewart22-Jul-04 12:29
protectorHeath Stewart22-Jul-04 12:29 
Generalthe process and services... Pin
Wail A.Salem22-Jul-04 11:58
Wail A.Salem22-Jul-04 11:58 
GeneralRe: the process and services... Pin
Heath Stewart22-Jul-04 12:39
protectorHeath Stewart22-Jul-04 12:39 
QuestionGetTextExtent? Pin
Matt Gerrans22-Jul-04 10:01
Matt Gerrans22-Jul-04 10:01 
AnswerRe: GetTextExtent? Pin
Gary Thom22-Jul-04 10:06
Gary Thom22-Jul-04 10:06 
GeneralRe: GetTextExtent? Pin
Matt Gerrans22-Jul-04 19:25
Matt Gerrans22-Jul-04 19:25 
GeneralRun external program and wait Pin
Boaz V22-Jul-04 9:06
Boaz V22-Jul-04 9:06 
GeneralRe: Run external program and wait Pin
Heath Stewart22-Jul-04 9:25
protectorHeath Stewart22-Jul-04 9:25 
GeneralAtt: Heath Stewart - Browser Helper Objects Pin
Stuggo22-Jul-04 8:46
Stuggo22-Jul-04 8:46 
GeneralRe: Att: Heath Stewart - Browser Helper Objects Pin
Heath Stewart22-Jul-04 9:08
protectorHeath Stewart22-Jul-04 9:08 
GeneralCOM Ports Pin
eggie522-Jul-04 7:09
eggie522-Jul-04 7:09 
GeneralRe: COM Ports Pin
eggie522-Jul-04 7:42
eggie522-Jul-04 7:42 
GeneralRe: COM Ports Pin
Jae Sammy22-Jul-04 7:51
Jae Sammy22-Jul-04 7:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.