Tabs and ComboBoxes Repost

G

Guest

How can I keep the ComboBox textbox empty of datasource items when my local
application starts AND keep them empty even after the user clicks different
Tabs on the form.

I welcome any questions. The problem isn’t clearing the items from the CB
textbox, the problem is I can’t keep them empty when the user moves around
the Tabs on the form. Each Tab has more CB’s and, by the way of course, I
need to keep user CB selections on each Tab.

I think I can solve the problem by adding whitespace to the CB datasource
(dB Table/Dataset). Do I need a Leave() event and variable for each CB? Tab
Event? Suggestions welcome. I can't let this go.

Previous pos
http://www.microsoft.com/communitie...05eb74-be55-441d-bfe4-e1376e9f7200&sloc=en-us
 
B

Bart Mermuys

Hi,

Steve B. said:
How can I keep the ComboBox textbox empty of datasource items when my
local
application starts AND keep them empty even after the user clicks
different
Tabs on the form.

I welcome any questions. The problem isn't clearing the items from the CB
textbox, the problem is I can't keep them empty when the user moves around
the Tabs on the form. Each Tab has more CB's and, by the way of course, I
need to keep user CB selections on each Tab.

I think I can solve the problem by adding whitespace to the CB datasource
(dB Table/Dataset). Do I need a Leave() event and variable for each CB?
Tab
Event? Suggestions welcome. I can't let this go.

Previous post
http://www.microsoft.com/communitie...05eb74-be55-441d-bfe4-e1376e9f7200&sloc=en-us

When switching tabs BindingContextChanged (unnecessary) fires, when
BindingContextChanged is fired it also updates ComboBox.SelectedIndex from
CurrencyManager.Position. CurrencyManager.Position can only be -1 if the
list is empty, otherwise 0, so that's why each time the first item gets
selected when switching tabs.

By default, Control's use the BindingContext from the parent Form
implicitly. Assigning the Form's BindingContext _explicitly_ to the
ComboBox solves the problem.

eg. inside a Form:
comboBox1.BindingContext = this.BindingContext;
comboBox1.DataSource = .... ;
comboBox1.SelectedIndex = -1;
comboBox1.SelectedIndex = -1; // twice because of another bug


Note: that in NET2.0 both bugs are gone.

HTH,
Greetings
 
G

Guest

Bart,

Thank You

I figured it had to be something like that (I know about the two -1's), but
where do I put your code; in a Tab event? and what about the user selection.
Anyways, I'll try to implement your suggestion, any more info is appreciated

Steve
 
B

Bart Mermuys

Hi,

Steve B. said:
Bart,

Thank You

I figured it had to be something like that (I know about the two -1's),
but
where do I put your code; in a Tab event? and what about the user
selection.
Anyways, I'll try to implement your suggestion, any more info is
appreciated

You want the ComboBox's to be cleared (even when the user switches tabs)
until the user selects something, right ? If so then all you should have to
do is run the code in the previous post just once, eg. at Form load, no need
to use tab events.

Form_Load:
comboBox1.BindingContext = this.BindingContext;
...

hth,
Greetings
 
G

Guest

Bart,

I want/wish to thank you very much it appears that works excellent, I can't
tell you the hours I spent... One of the problems I have with the framework
is understanding what exactly is a binding, bindingContext, currencyManager,
etc so every time I run against it - I have a problem.

Bart, in a different matter, I'm sort of at a turning point with this local
ADO.Net application and would like to hear your comments on couple serous
problems I'm having, for example, I'm not sure if its the structure problem
or the underlying database.

I'd like to pose the questions to you if I can, please let me know.

Steve
 
B

Bart Mermuys

Hi,

Steve B. said:
Bart,

I want/wish to thank you very much it appears that works excellent, I
can't
tell you the hours I spent... One of the problems I have with the
framework
is understanding what exactly is a binding, bindingContext,
currencyManager,
etc so every time I run against it - I have a problem.

To put it simple:
A BindingContext is a collection (map) that contains PropertyManager's
and/or CurrencyManager's. By default each Form has a BindingContext and is
implicitly shared by the controls.
A CurrencyManager is used when you bind to a list and it manages the
position and Binding's.
A PropertyManagers is used when you bind to a single object and it manages
Binding's.
Internally a Binding binds a Control property to a CurrencyManager or
PropertyManager.
Bart, in a different matter, I'm sort of at a turning point with this
local
ADO.Net application and would like to hear your comments on couple serous
problems I'm having, for example, I'm not sure if its the structure
problem
or the underlying database.

I'd like to pose the questions to you if I can, please let me know.

You may get a 'broader' response if you ask it to a related newsgroup, but
if you want, you can email me, remove the spam part.

HTH,
Greetings
 
G

Guest

Thanks Bart. I tried to be brief below

I’m using VS for development. My local application is described as a top
level simple form with dropdown menus. The items in the menu link to
internal MS-Office network share drive documents or web pages. A couple of
these menu items link to an ADO.Net Interface in which the underlying dB is
MS-Access. The Interfaces provides Add, Delete, Change, DataGrid/dB
functionality. The adjacent bound DG ComboBoxes on the form display’s the
“selected†row in the DG

One of these Interfaces is quite complex containing approx 110 string fields
in the Main table of the dB. The ADO.Net interface that addresses this Main
table is modeled after a simpler Interface of 15 fields that works fine.
Both the simple and complex ADO.Net Interfaces utilize a common inherited
Interface file/class containing all the common ADO.Net methods.

Problem #1
FYI, the VS DataAdapter wizard limits itself to 100 fields. So I said O’K,
let’s do 90 fields and worry about the other ones later and get 90 working
and loaded. The 90 fields loaded into the DG and associated CB’s fine.
Here’s the problem, I can’t manipulate the data. If I try to change a field
in one of the 90 fields of the DG and try to save this Update to the dB I’ll
get a “Expression is to Complex†error message. I haven't bther tring the
other functionalities.

Proposed Solution #1
I’m going to strip the DA and DS from the automatically generated
InitializeComponent() code and put it all manually in my code. I hope this
stops the error and allows me to add the 110 fields. I’m doing that now.
Comments? Let me also say I recognize dB Normalization.

Problem #2
The complex Interface discussed above is a dll which is developed/debugged
on my machine and then the whole application is Released compiled to the
network. The problem is that sometimes and only sometimes the dll won’t
close(). I don’t know if a user doesn’t close it properly but I can’t trace
the problem. There’s only one thread in the program and I’ve tried stuff
like GC. All I know is when I try to Release compile I get an error message
saying basically that can’t compile that portion of the application because
that file is open and the file is definitely not open at 5:30am.

Fix #2
I have to get the IT guy, go to the server open all the running process on
the server, find my running database dll process and close it. I can’t see
it locally on my machine. After that I can Release compile fine. Why
doesn’t the dll close?

Problem #3 (BUG?)
When the program is not running and if I click on a Tab full of bound CB’s
and have focus on a Tab and then try to close VS I get the following error
massage: “The following exception has occurred, DataBinding could not find a
row in the list suitable for all bindingsâ€..Is this a bug or a sign of the
stability of my program?

Will SQL Server help me in general?
My next step is contacting MS for assistance.

Steve
 
B

Bart Mermuys

Hi,

Steve B. said:
Thanks Bart. I tried to be brief below

I'm using VS for development. My local application is described as a top
level simple form with dropdown menus. The items in the menu link to
internal MS-Office network share drive documents or web pages. A couple
of
these menu items link to an ADO.Net Interface in which the underlying dB
is
MS-Access. The Interfaces provides Add, Delete, Change, DataGrid/dB
functionality. The adjacent bound DG ComboBoxes on the form display's the
"selected" row in the DG

One of these Interfaces is quite complex containing approx 110 string
fields
in the Main table of the dB. The ADO.Net interface that addresses this
Main
table is modeled after a simpler Interface of 15 fields that works fine.
Both the simple and complex ADO.Net Interfaces utilize a common inherited
Interface file/class containing all the common ADO.Net methods.

Problem #1
FYI, the VS DataAdapter wizard limits itself to 100 fields. So I said O'K,
let's do 90 fields and worry about the other ones later and get 90 working
and loaded. The 90 fields loaded into the DG and associated CB's fine.
Here's the problem, I can't manipulate the data. If I try to change a
field
in one of the 90 fields of the DG and try to save this Update to the dB I'll
get a "Expression is to Complex" error message. I haven't bther tring the
other functionalities.

Proposed Solution #1
I'm going to strip the DA and DS from the automatically generated
InitializeComponent() code and put it all manually in my code. I hope
this
stops the error and allows me to add the 110 fields. I'm doing that now.
Comments? Let me also say I recognize dB Normalization.

You're getting "Expression is to Complex" because the generated update query
checks whether the old values are still the same to provide optimistic
concurrency, but this causes a lot of AND's in the WHERE clause and the
number is limited with Jet to 40. You could create your own query whithout
checking the old values (no ANDs) but then you loose optimistic concurrency
control. I've never dealt with that many columns.
Problem #2
The complex Interface discussed above is a dll which is developed/debugged
on my machine and then the whole application is Released compiled to the
network. The problem is that sometimes and only sometimes the dll won't
close(). I don't know if a user doesn't close it properly but I can't
trace
the problem. There's only one thread in the program and I've tried stuff
like GC. All I know is when I try to Release compile I get an error
message
saying basically that can't compile that portion of the application
because
that file is open and the file is definitely not open at 5:30am.

Fix #2
I have to get the IT guy, go to the server open all the running process on
the server, find my running database dll process and close it. I can't
see
it locally on my machine. After that I can Release compile fine. Why
doesn't the dll close?

No idea why the dll remains open. If you are using threads then makes sure
they end when the program gets closed. If non-background threads aren't
ended they keep your program running.
Problem #3 (BUG?)
When the program is not running and if I click on a Tab full of bound CB's
and have focus on a Tab and then try to close VS I get the following error
massage: "The following exception has occurred, DataBinding could not
find a
row in the list suitable for all bindings"..Is this a bug or a sign of the
stability of my program?

That sounds like a bug.
Will SQL Server help me in general?

There is a lot of difference between sqlserver and access, first of all
access is a file database while sql server is a server database. A lot of
people don't consider access a "real" database. But you should be able to
find lots of information (about the differences) on the internet.

Sorry i couldn't be more helpfull, maybe someone else might still help.

Greetings
 
G

Guest

Thank You Bart. I was hoping SQL Server might solve problem 1. I do start a
thread when the program starts to tell the user if the program is already
running but anyways thank you for you time.

Steve
 
G

Guest

Bart ,

I been working with the bindingcontext since your last e-mail, however,
there's one problem I can't solve. I have an intial ADO.Net form that opens
up and displays the contents of dB in a DataGrid. Adjacent to the DG are
ComboBoxes that are databound in that when you change a row in the DG it
displays the row info in the CB's.

While the base Tab on the form displays basic part data the 4 additional
tabs display the 25 dimensional characteristics for the part. The
properties. or codes. for each of the 25 characteristics are exactly the same
set of data and are contained in the CB dropdowns.

The problem is I had to create 25 Datasets for each of the characteristic
properties/codes CB's (e.g. all the DS contain exactly the same info). The
question is with a DataBinding of the form, how do assign one DS for all the
CB's. I've tried lots of things and all kinds of BindingContext variations
(new, in code. etc).

Thanks
Steve

Example:

this.charaCode1CB.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.csiDbDS, "Main.CharacteristicCodes1"));
this.charaCode1CB.DataSource = this.charaCodeDS1;
this.charaCode1CB.DisplayMember = "CharacteristicTypes.CharacteristicType";
*************
this.charaCode2CB.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.csiDbDS, "Main.CharacteristicCodes2"));
this.charaCode2CB.DataSource = this.this.charaCodeDS2;
this.charaCode2CB.DisplayMember = "CharacteristicTypes.CharacteristicType";
..
..
..
 
B

Bart Mermuys

Hi,

Steve B. said:
Bart ,

I been working with the bindingcontext since your last e-mail, however,
there's one problem I can't solve. I have an intial ADO.Net form that
opens
up and displays the contents of dB in a DataGrid. Adjacent to the DG are
ComboBoxes that are databound in that when you change a row in the DG it
displays the row info in the CB's.

While the base Tab on the form displays basic part data the 4 additional
tabs display the 25 dimensional characteristics for the part. The
properties. or codes. for each of the 25 characteristics are exactly the
same
set of data and are contained in the CB dropdowns.

The problem is I had to create 25 Datasets for each of the characteristic
properties/codes CB's (e.g. all the DS contain exactly the same info).
The
question is with a DataBinding of the form, how do assign one DS for all
the
CB's. I've tried lots of things and all kinds of BindingContext
variations
(new, in code. etc).

Thanks
Steve

Example:

You explained what you're doing but not what the problem is you're having.
I assume all ComboBox's navigated thogether, because they had the same
DataSource and same BindingContext. You can't use a different
BindingContext for each ComboBox because of the fact that they still need
the same CurrencyManager for the master table ( csiDbDS.Main ). So the best
way to deal with this is using a different DataView for each ComboBox:

this.charaCode1CB.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.csiDbDS, "Main.CharacteristicCodes1"));
this.charaCode1CB.DataSource = new
DataView(this.charaCodeDS1.Tables["CharacteristicTypes"]);
this.charaCode1CB.DisplayMember = "CharacteristicType";

this.charaCode2CB.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.csiDbDS, "Main.CharacteristicCodes2"));
this.charaCode2CB.DataSource = new
DataView(this.charaCodeDS1.Tables["CharacteristicTypes"]);
this.charaCode2CB.DisplayMember = "CharacteristicType";


HTH,
Greetings
 
G

Guest

Bart,

You’re a genius thank you it appears to work fine.

Thank You very much, again
Steve


Bart Mermuys said:
Hi,

Steve B. said:
Bart ,

I been working with the bindingcontext since your last e-mail, however,
there's one problem I can't solve. I have an intial ADO.Net form that
opens
up and displays the contents of dB in a DataGrid. Adjacent to the DG are
ComboBoxes that are databound in that when you change a row in the DG it
displays the row info in the CB's.

While the base Tab on the form displays basic part data the 4 additional
tabs display the 25 dimensional characteristics for the part. The
properties. or codes. for each of the 25 characteristics are exactly the
same
set of data and are contained in the CB dropdowns.

The problem is I had to create 25 Datasets for each of the characteristic
properties/codes CB's (e.g. all the DS contain exactly the same info).
The
question is with a DataBinding of the form, how do assign one DS for all
the
CB's. I've tried lots of things and all kinds of BindingContext
variations
(new, in code. etc).

Thanks
Steve

Example:

You explained what you're doing but not what the problem is you're having.
I assume all ComboBox's navigated thogether, because they had the same
DataSource and same BindingContext. You can't use a different
BindingContext for each ComboBox because of the fact that they still need
the same CurrencyManager for the master table ( csiDbDS.Main ). So the best
way to deal with this is using a different DataView for each ComboBox:

this.charaCode1CB.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.csiDbDS, "Main.CharacteristicCodes1"));
this.charaCode1CB.DataSource = new
DataView(this.charaCodeDS1.Tables["CharacteristicTypes"]);
this.charaCode1CB.DisplayMember = "CharacteristicType";

this.charaCode2CB.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.csiDbDS, "Main.CharacteristicCodes2"));
this.charaCode2CB.DataSource = new
DataView(this.charaCodeDS1.Tables["CharacteristicTypes"]);
this.charaCode2CB.DisplayMember = "CharacteristicType";


HTH,
Greetings
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top