|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
data bound combobox does not leave focusI'm quite new to database development and am trying Visual Studio with ADO.NET for the first time (Borland user before). So please apologize my lack of experience with the tool. (More precise, I'm using MS Visual C# 2005 Express) I have two test tables in a JET database. For simplicity say: Table1: Samples ID PersonID SomeOtherColumn Table2: Persons ID Name SomeOtherColumn I created a new data source in VS studio using the mdb file I created in MS Access before. VS generated typed wrapper classes for the tables. Then I wanted to automatically create a simple form for the 'Samples'-table. Since the form should display Person-Names instead of the PersonID I changed the control type for PersonID to ComboBox in the DataSource editor. Then I dragged the 'Samples'-table to the form. All controls were generated fine. I then set the DataSource of the PersonID Combobox to the generated personsBindingSource, DisplayMember to 'Name' and ValueMember to 'ID'. Problem: I start the test application and the database is loaded. (the Samples table is empty while the Persons table contains a few test persons) Using the automatically generated bindingNavigator I create a new record in the Samples table. Now I want to set the PersonID field in the ComboBox. On drop-down all names contained in the Persons table are correctly displayed and I can select one of the names. After that, however, I can't leave the ComboBox!! It looks like the validation fails and the focus always returns back to the ComboBox. I can't even close the application. I thought that given the above mentioned settings ADO would automatically get the correct ID from the selected name? But it looks more like it tries to type-convert the selected name to the ID, what fails. Any ideas? I should mention that I tried the same with a ListBox instead of ComboBox and that seems to work correctly!!! I also googled for posts on related issues but couldn't find anything that matches this particular issue. If more information is needed please ask!! thanks for any help, Nicolas Nicolasr,
I don't understand something in your question. As I read it well you say that you set the in the datasource "combobox". Normally you set in a Combobox a datasource (plus it displaymember and valuemember) What is it that I miss? Cor Show quote "nicolasr" <nicolasrNOSPAMATSIGNgmx.net> schreef in bericht news:uYtXWsNZGHA.3752@TK2MSFTNGP03.phx.gbl... > Hi, > > I'm quite new to database development and am trying > Visual Studio with ADO.NET for the first time (Borland > user before). So please apologize my lack of experience > with the tool. (More precise, I'm using MS Visual C# 2005 Express) > > I have two test tables in a JET database. For simplicity say: > > Table1: Samples > ID > PersonID > SomeOtherColumn > > Table2: Persons > ID > Name > SomeOtherColumn > > I created a new data source in VS studio using the mdb file > I created in MS Access before. VS generated typed wrapper > classes for the tables. Then I wanted to automatically create > a simple form for the 'Samples'-table. Since the form should > display Person-Names instead of the PersonID I changed the > control type for PersonID to ComboBox in the DataSource > editor. > Then I dragged the 'Samples'-table to the form. All controls > were generated fine. I then set the DataSource of the PersonID > Combobox to the generated personsBindingSource, DisplayMember > to 'Name' and ValueMember to 'ID'. > > Problem: > I start the test application and the database is loaded. (the Samples > table is empty while the Persons table contains a few test persons) > Using the automatically generated bindingNavigator I create a > new record in the Samples table. Now I want to set the PersonID field > in the ComboBox. On drop-down all names contained in the Persons > table are correctly displayed and I can select one of the names. > After that, however, I can't leave the ComboBox!! It looks like > the validation fails and the focus always returns back to the ComboBox. > I can't even close the application. > > I thought that given the above mentioned settings ADO would automatically > get the correct ID from the selected name? But it looks more like it > tries to type-convert the selected name to the ID, what fails. > > Any ideas? > > I should mention that I tried the same with a ListBox instead of ComboBox > and that seems to work correctly!!! I also googled for posts on related > issues > but couldn't find anything that matches this particular issue. > > If more information is needed please ask!! > > thanks for any help, > Nicolas > thanks for your reply and sorry for the confusion.
What I meant was just that I changed the control-type in the tab on the left side named "Data Sources" to ComboBox. After the form is automatically generated it is as you say. I selected the generated ComboBox and set its DataSource property, set DisplayMember and ValueMember. Hope it makes more sense now? Again, the problem seems to be, that the DisplayMember refers to a string type (the "Name") while the ValueMember refers to "ID" which is integer. Nicolas Show quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb im Newsbeitrag news:e88ryTRZGHA.3972@TK2MSFTNGP04.phx.gbl... > Nicolasr, > > I don't understand something in your question. As I read it well you say > that you set the in the datasource "combobox". Normally you set in a > Combobox a datasource (plus it displaymember and valuemember) > > What is it that I miss? > > Cor > > > "nicolasr" <nicolasrNOSPAMATSIGNgmx.net> schreef in bericht > news:uYtXWsNZGHA.3752@TK2MSFTNGP03.phx.gbl... >> Hi, >> >> I'm quite new to database development and am trying >> Visual Studio with ADO.NET for the first time (Borland >> user before). So please apologize my lack of experience >> with the tool. (More precise, I'm using MS Visual C# 2005 Express) >> >> I have two test tables in a JET database. For simplicity say: >> >> Table1: Samples >> ID >> PersonID >> SomeOtherColumn >> >> Table2: Persons >> ID >> Name >> SomeOtherColumn >> >> I created a new data source in VS studio using the mdb file >> I created in MS Access before. VS generated typed wrapper >> classes for the tables. Then I wanted to automatically create >> a simple form for the 'Samples'-table. Since the form should >> display Person-Names instead of the PersonID I changed the >> control type for PersonID to ComboBox in the DataSource >> editor. >> Then I dragged the 'Samples'-table to the form. All controls >> were generated fine. I then set the DataSource of the PersonID >> Combobox to the generated personsBindingSource, DisplayMember >> to 'Name' and ValueMember to 'ID'. >> >> Problem: >> I start the test application and the database is loaded. (the Samples >> table is empty while the Persons table contains a few test persons) >> Using the automatically generated bindingNavigator I create a >> new record in the Samples table. Now I want to set the PersonID field >> in the ComboBox. On drop-down all names contained in the Persons >> table are correctly displayed and I can select one of the names. >> After that, however, I can't leave the ComboBox!! It looks like >> the validation fails and the focus always returns back to the ComboBox. >> I can't even close the application. >> >> I thought that given the above mentioned settings ADO would automatically >> get the correct ID from the selected name? But it looks more like it >> tries to type-convert the selected name to the ID, what fails. >> >> Any ideas? >> >> I should mention that I tried the same with a ListBox instead of ComboBox >> and that seems to work correctly!!! I also googled for posts on related >> issues >> but couldn't find anything that matches this particular issue. >> >> If more information is needed please ask!! >> >> thanks for any help, >> Nicolas >> > > |
|||||||||||||||||||||||