all groups > dotnet windows forms databinding > december 2007 >
You're in the

dotnet windows forms databinding

group:

Cant leave databinded comboboxes


Cant leave databinded comboboxes erah
12/18/2007 2:56:01 AM
dotnet windows forms databinding:
Hi!

I have som problems using drag n drop functionallity in visualstudio 2005.

I have created a dataset from my sqlexpress with one main table and three
valuetables using IDnumbers to get the realname of each child..

I then created a datagridview and changed the IDvalues ( FKs ) to databinded
comboboxes to display the correct values. So far so good all values are
displayed correctly!

When I try to drag n drop the detail ( as comboboxes ) these are to be used
to select values to change/add the data in the datagrid.
the bindings are set as follows:

Datasource: NameBindingSource
Displaymember: Name
Value Member: NameID
Selected Value: MainBindingSource - NameID

This works as long as I only use ONE combobox, if I add anotherone from
another table as follows:

Datasource: LastNameBindingSource
DisplayName: LastName
Value Member: LastNameID
Selected Value: MainBindingSource - LastNameID

The result will be that when I select a LastName I cant leave that combobx.
No other event will respond, the only solution is to kill the application.

Today I noticed that if I manually add numeric values to in my database it
will work for the numeric values only.

Is this a known bug or is it me using bindings the wrong way?

I have a ready example to upload if theres anyone interested in this problem.
--
kind regards Erik
RE: Cant leave databinded comboboxes Morten Wennevik [C# MVP]
12/20/2007 3:38:00 AM
Hi Erik,

Without knowing the details it looks like you encounter some kind of eternal
loop, although I could not reproduce your problem using a BindingList as
source for two BindingSources. Selecting a person from the second comboBox
would update NameID of the selected person from the first ComboBox

My setup code was as follows. Person is a business object having a string
Name and int Id property

Person personA = new Person("Pete", 1);
Person personB = new Person("James", 2);
Person personC = new Person("Richard", 3);
_personList.Add(personA);
_personList.Add(personB);
_personList.Add(personC);

dataGridView1.DataSource = _personList;

sourceMain = new BindingSource(_personList, "");
sourceLast = new BindingSource(_personList, "");

comboBox1.DataSource = sourceMain;
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "Id";

comboBox2.DataSource = sourceLast;
comboBox2.DisplayMember = "Name";
comboBox2.ValueMember = "Id";

comboBox2.DataBindings.Add("SelectedValue", sourceMain, "Id");

--
Happy Coding!
Morten Wennevik [C# MVP]


[quoted text, click to view]
RE: Cant leave databinded comboboxes Erik
1/3/2008 7:06:03 AM
Yes that works fine but..

Im using visual studio 2005 ( latest service packs and so on )

Im using autogeneratade code first by creating a Dataset thru the guide in
"datasources"
when thats done Im creating a datagrid from "data Source" and all fields
created the same way ( like in the instruction videos )

everything is so far connected automatically ..

using four tables I get 4 bindingsources and 4 table adapters.
the main table has FKs to the 3 valuetables where I get the names I want to
display.

Is there someplace I can upload an example I ve created.. ?

If I in one combobox select a vaule that doesnt work I can select a
different value and the "lock" will go away I can even select the value that
caused the lock.

I have 3 developers working with this issue and noone of them has come up
with a solution .. we are getting out of Ideas
(We can reproduce the error only with 2 or more comboboxes)

kind regards Erik



[quoted text, click to view]
AddThis Social Bookmark Button