473,729 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combobox and eventhandler

Hi,

I have a combobox and datagrid in a form. When an Item is selected from a
combobox, a method is called, which will make selection from a database
according selected item and populate datagrid.

I used comboBoxLastNam e_SelectedValue Changed handler, but this handler is
called for every Item when combobox is initialized at the start. It means
there is made database access for every item, which is not needed and slows
down application.

What is the best place for calling that method?

Thank you.

Lubomir

Nov 16 '05 #1
3 3271
Hitting the db each time anything happens, regardless of the event, is
probably a bad idea. The shortcut way would be to define a flag and just
e.Cancel the event if that flag isn't set. When the form is done
initializing then go ahead and set the flag. The order of what happens and
what events fire when the form is initializing isn't a constant thing so
it's pretty hard to handle otherwise. So basically, at the end of the form
loading, set IsLoading to false. Then in your event handler,
if(IsLoading)re turn;

Ok, now for the real problem. If you are hitting the db each time a combobox
value is selected, you are defintiely wasting a lot of resources and it's a
rare scenario indeed where this is necessary. For instance, if I select the
first value in the combobox, then realize I made a mistake and try to click
the second one, and then realize it was actually the first one after all
taht I wanted, I just made three trips to the DB. This may not appear to be
really wasteful if I only have a few users, but as the user base grows, this
type of approach will not scale. I would consider (depending on the schema
of the db), pulling over the parent and child tables (if they fit that
paradigm) or pulling over the respective tables at once. If they fit the
parent child model, I'd link them w/ a datarelation and set the bindings
accordingly - this way I don't have to make a trip back to the db each time.
http://www.knowdotnet.com/articles/datarelation.html If they don't fit this
model, I'd consider binding to a dataview for instance and setting the
RowFilter property (or use Find or Datatable.Selec t)
http://www.knowdotnet.com/articles/expressions.html
http://www.knowdotnet.com/articles/adopartiii.html

And even if you must go to the db, I'd use some structure of my own if I
couldn't use a DataTable or a View to hold values that I already retrieved
so that if the users selects soemthing they already selected, I can just
grab it from the local store and save a trip to the db and all of the
overhead associated with it.

HTH,

Bill

--
W.G. Ryan MVP Windows - Embedded

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/...ity/newsgroups
"Lubomir" <Lu*****@discus sions.microsoft .com> wrote in message
news:1E******** *************** ***********@mic rosoft.com...
Hi,

I have a combobox and datagrid in a form. When an Item is selected from a
combobox, a method is called, which will make selection from a database
according selected item and populate datagrid.

I used comboBoxLastNam e_SelectedValue Changed handler, but this handler is
called for every Item when combobox is initialized at the start. It means
there is made database access for every item, which is not needed and slows down application.

What is the best place for calling that method?

Thank you.

Lubomir

Nov 16 '05 #2
On 2004-08-16, William Ryan eMVP <do********@com cast.nospam.net > wrote:
Ok, now for the real problem. If you are hitting the db each time a combobox
value is selected, you are defintiely wasting a lot of resources and it's a
rare scenario indeed where this is necessary.
I'd disagree there, but it's pretty hard to define "rare". Choices like
this obviously depend on the app.

But in my experience, it's pretty common to have the situation where
pulling down complete tables isn't a reasonable option. Startup time
and memory usage can skyrocket if one uses your approach.
For instance, if I select the
first value in the combobox, then realize I made a mistake and try to click
the second one, and then realize it was actually the first one after all
taht I wanted, I just made three trips to the DB.
Agreed, a simple caching scheme is reasonable here.
This may not appear to be
really wasteful if I only have a few users, but as the user base grows, this
type of approach will not scale. I would consider (depending on the schema
of the db), pulling over the parent and child tables (if they fit that
paradigm) or pulling over the respective tables at once.


If scalability is the issue, having every client that connects pull down
complete tables is unlikely to be the solution, unless your app fits
some very narrow assumptions. And regardless of scalability, stale data
may be a serious issue, which may preclude the option of caching the
complete dataset.

I can easily imagine apps where this approach is the correct one, just
as I can easily imagine apps where this approach is a very bad idea.
I've worked on both. It all depends on dataset size, user base size,
type of application, requirements, phase of the moon, etc.

I agree that caching the complete dataset is an idea worth considering,
but I don't believe it should be presented as an approach that's almost
universally correct.

Nov 16 '05 #3
Hi,
Thanks for your answers (William and David). Yes, I used parent/child
relations ship and I defined a row filter for a combobox. However there are
more comboboxex, which are used when it is needed to change a criteria for a
SELECT statement. This is the case, when it is needed to access the database.

Yes, I agree, a combo box is too easy way to a database, and I will consider
to put there a button, that will be needed to click after the selection in
combobox was made.

I don't think this application will be used by more than 5 people at the
same time, but the one never knows... :-)

Thanks for your ideas.

Lubomir
"David" wrote:
On 2004-08-16, William Ryan eMVP <do********@com cast.nospam.net > wrote:
Ok, now for the real problem. If you are hitting the db each time a combobox
value is selected, you are defintiely wasting a lot of resources and it's a
rare scenario indeed where this is necessary.


I'd disagree there, but it's pretty hard to define "rare". Choices like
this obviously depend on the app.

But in my experience, it's pretty common to have the situation where
pulling down complete tables isn't a reasonable option. Startup time
and memory usage can skyrocket if one uses your approach.
For instance, if I select the
first value in the combobox, then realize I made a mistake and try to click
the second one, and then realize it was actually the first one after all
taht I wanted, I just made three trips to the DB.


Agreed, a simple caching scheme is reasonable here.
This may not appear to be
really wasteful if I only have a few users, but as the user base grows, this
type of approach will not scale. I would consider (depending on the schema
of the db), pulling over the parent and child tables (if they fit that
paradigm) or pulling over the respective tables at once.


If scalability is the issue, having every client that connects pull down
complete tables is unlikely to be the solution, unless your app fits
some very narrow assumptions. And regardless of scalability, stale data
may be a serious issue, which may preclude the option of caching the
complete dataset.

I can easily imagine apps where this approach is the correct one, just
as I can easily imagine apps where this approach is a very bad idea.
I've worked on both. It all depends on dataset size, user base size,
type of application, requirements, phase of the moon, etc.

I agree that caching the complete dataset is an idea worth considering,
but I don't believe it should be presented as an approach that's almost
universally correct.

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
12281
by: Microsoft | last post by:
Hi All, Any suggestions appreciated. I am trying to do a string search through a comboBox list, have created a simple test which is listed below. The problem I am having is, every time a key is pressed it echoes the char back to the combo twice. For example, if I type D in the combo I get back Dd. The following app works OK if I use KeyPress instead of KeyDown/KeyUp on my computer, but if I run it on another computer (with .NET...
3
4270
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found several examples on the web. They all seem to have problems, though that I've been unable to resolve. The most promising example I have found is at:
0
2664
by: Hiroyuki Tanaka | last post by:
Hi All, I am trying to develop an application for a touch screen using buttons for the numeric pad with Completion ComboBoxes. At the moment I am having a problem sending the button presses to my Completion ComboBox using sendkey.wait. From the keyboard (that will not exist for my final application) I can enter text into my Completion and the selection completes as expected.
3
3028
by: PeterZ | last post by:
G'day, After doing much searching and pinching bits of ideas from here there and everywhere I came up with a fairly 'clean' solution of including a comboBox into a dataGrid column. You can download a fully working C# sample with the Northwind.mdb here: www.insightgis.com.au/web/stuff/DataGridCombo.zip
2
4332
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know how to use this code? please help! http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20862953.html
3
6832
by: TT (Tom Tempelaere) | last post by:
Hay there, I'm writing my own DataGridComboBoxColumn because .NET 1.1 does not have one (I hope .NET 2.0 supplies one). I based it on this article: http://msdn.microsoft.com/msdnmag/issues/03/08/DataGrids/default.aspx I have a problem when there are two DataGrid's on one form, and when I switch focus from one grid to the other. To be more precise, when I'm editing a combo box column in one grid, and then click in the combo column of...
0
2052
by: Doug | last post by:
This is a repost of an item that I still cannot resolve. I have 3 combo boxes. The first leads to the second to the third. When I have selected a value in the second box, the third box shows the available information based on the second combo box selection. But if I change my mind and select a different item in the second box, after the third box has been populated, the third box still retains the information that was previously...
0
1478
by: | last post by:
Hi All. I have a problem with combobox, what I want is when combobox gets focus I need it to show the dropdown list t.This is fine if the user selects the combobox via keystrokes but when the combobox is selected via mouse click it draws the dropdown list twice. As I am trapping the enter event, I can see thats is called as well some other ? the style is set to dropdownlist as they must select one from the list I assume I must trap a...
1
3372
by: polocar | last post by:
Ciao a tutti, leggendo qua e là per il forum ho scoperto che non sono l'unico ad avere questo problema. Se si inserisce un controllo ComboBox in un form di C#, non è possibile impostare la sua altezza ad un valore diverso da 21. Forse, cambiando la dimensione del font, si potrebbe riuscire a cambiare anche l'impostazione dell'altezza... (MS farebbe comunque meglio ad introdurre per il ComboBox una proprietà AutoSize impostabile a "false"...
2
1279
by: arevans | last post by:
I built a custom control 'ChooseBox' that inherits from ComboBox. When I select an item from a choosebox control, the selected item does not show up; I mean, the background is blue, but the text is hidden. I have checked my backcolor and forecolor, and don't see anything wrong there. I know this is probably a simple q. Here is the code. Can anybody help? arevans using System; using System.Collections.Generic; using...
0
9284
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9148
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4528
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4796
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2165
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.