I have some code that I put in the Before_Dropdown event of a combobox field
on a winform. It works but only because I am making use of a public
boolean variable called IveFilledCompan ys. The code follows:
If IveFilledCompan ys = False Then
SqlConnection1. Open()
Dim SqlReader As System.Data.Sql Client.SqlDataR eader
SqlReader = SqlCommand1.Exe cuteReader()
While SqlReader.Read
cboCompanys.Ite ms.Add(SqlReade r.Item("Company "))
End While
SqlReader.Close ()
SqlConnection1. Close()
IveFilledCompan ys = True
End If
I would like to keep the use of public variables to a minimum. I wonder if
there is another way to write this code without the variable. Basically, I
would like the code (upon arrival on the combobox field) to fill the
combobox with data if it has not already been filled. I thought perhaps
something like the following would work, again, this is in the
BeforeDropDown event.
Dim iCount As Integer = cboCompanys.Dat aBindings.Count ()
If iCount <= 1 Then
... fill the table code
Else
MsgBox("It's already been filled. Do nothing")
End If
However, I find that when running my code iCount never equals anything but
1.
Anyone have any ideas on how I can accomplish what I want? 3 2982
New here, but why dont you just change your code to read: If cboCompany.Item s.Count = 0 Then SqlConnection1. Open() Dim SqlReader As System.Data.Sql Client.SqlDataR eader SqlReader = SqlCommand1.Exe cuteReader() While SqlReader.Read cboCompanys.Ite ms.Add(SqlReade r.Item("Company ")) End While SqlReader.Close () SqlConnection1. Close() IveFilledCompan ys = True End If
"Woody Splawn" <wo***@splawns. com> wrote in message
news:eH******** ******@TK2MSFTN GP12.phx.gbl... I have some code that I put in the Before_Dropdown event of a combobox
field on a winform. It works but only because I am making use of a public boolean variable called IveFilledCompan ys. The code follows:
If IveFilledCompan ys = False Then SqlConnection1. Open() Dim SqlReader As System.Data.Sql Client.SqlDataR eader SqlReader = SqlCommand1.Exe cuteReader() While SqlReader.Read cboCompanys.Ite ms.Add(SqlReade r.Item("Company ")) End While SqlReader.Close () SqlConnection1. Close() IveFilledCompan ys = True End If
I would like to keep the use of public variables to a minimum. I wonder
if there is another way to write this code without the variable. Basically,
I would like the code (upon arrival on the combobox field) to fill the combobox with data if it has not already been filled. I thought perhaps something like the following would work, again, this is in the BeforeDropDown event.
Dim iCount As Integer = cboCompanys.Dat aBindings.Count () If iCount <= 1 Then ... fill the table code Else MsgBox("It's already been filled. Do nothing") End If
However, I find that when running my code iCount never equals anything but 1.
Anyone have any ideas on how I can accomplish what I want?
>New here, but why dont you just change your code to read
That was a good suggestion. Thank you.
Hi Woody,
The iCount never changes because you didn't add any Databindings to the
ComboBox. The DataBindings.Co unt property increases only when you use
DataBindings.Ad d() method to add a binding to a data source. When you
called cboCompanys.Ite ms.Add(), you didn't make any changes to the
DataBindings property. Please try to use iCount = cboCompanys.Ite ms.Count,
and check if iCount >0 before adding items to it.
If anything is unclear, please feel free to reply to the post.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights." This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: hboothe_no_spam |
last post by:
Hello, all, I've read through both of the groups I'm posting to, and
all over the groups, regarding filling PDF forms with data from VB. I
have Acrobat 5 (and the SDK), and am using VB 6. I can successfully
place data in a field with code like the following (leaving out
declarations for brevity):
Set AdPre = CreateObject("AcroExch.AVDoc")
AdPre.Open "c:\test.pdf", "Foo"
Set formApp = CreateObject("AFormAut.App")
Set acroForm =...
|
by: Koen |
last post by:
Hi all,
My application uses a lot of lookup tables.
I've splitted the frontend (forms, reports, etc) from the backend (data).
The database has around 10 different users.
The values in the lookup tables are not likely to change.
Question 1: Should I include them in the backend (with rest of data) or the
frontend?
|
by: my-wings |
last post by:
I've been reading about how evil Lookup fields in tables are, but I've got
to be missing something really basic. I know this subject has been covered
before, because I've just spent an hour or two reading about it on google,
but there is something I still don't understand, and I'm hoping someone will
be willing to explain it to me in small words.
Let's say I have a table for addresses, and it includes a field for state.
What I would...
|
by: google |
last post by:
I have a database with four table. In one of the tables, I use about
five lookup fields to get populate their dropdown list. I have read
that lookup fields are really bad and may cause problems that are hard
to find. The main problem I am having right now is that I have a report
that is sorted by one of these lookup fields and it only displays the
record's ID number. When I add the source table to the query it makes
several records...
|
by: gillcleeren |
last post by:
I have a datagrid that has to be filled in a WinForms application. The
data comes from an Oracle database.
The normal procedure would be filling a dataset, but I have the problem
that there are over 100.000 records in the tables, so this has very low
performance when executing.
I then tried using an OracleDataReader, but for some reason, I cannot
bind my reader to the datagrid, I get the following error:
"Complex DataBinding accepts...
| |
by: LurfysMa |
last post by:
I am working on an electronic flashcard program. Most of the subjects
are simple lists of questions and answers. Those seem to be working.
Some of the "subjects" have "categories" of questions.
One example is a kind of trivia subject. There are several
"categories" such as "geography", "history", etc., like in the Trivial
Pursuit game. Each card has a question in each category.
|
by: Paul H |
last post by:
Suppose I have a table called tblPeople and I want a field to illustrate
whether each person prefers cats or dogs. I could do it one of three ways.
1. A plain text field
Create a text field in tblPeople called PreferredPet.
2. A lookup field that stores text values.
Create a text field in tblPeople called PreferredPetID and use it to lookup
an identical text field in tblPreferredPets.
|
by: tfurubay |
last post by:
Hi,
I am setting up an address reader in access. I'm hoping to create a form with a lookup field. When i enter an account number in the lookup field, i wish to return the customer name, address, etc in other fields. I tried doing this with the filter or find functions but this method is too cumbersome.
i know there is a way to build an expression using a lookup function but i am having trouble making it work. any help would be greatly...
|
by: Mark |
last post by:
I have a table with a field that uses a combobox to populate values. The
Lookup tab within table design mode is the following:
Display Control Combo Box
Row Source Type Table/Query
Row Source SELECT .LastName, .FirstName, .EmployeeNumber FROM ;
Bound Column 3
Column Count 3
Column Heads Yes
Column Widths 1";1";1"
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |