W
Woody Splawn
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 IveFilledCompanys. The code follows:
If IveFilledCompanys = False Then
SqlConnection1.Open()
Dim SqlReader As System.Data.SqlClient.SqlDataReader
SqlReader = SqlCommand1.ExecuteReader()
While SqlReader.Read
cboCompanys.Items.Add(SqlReader.Item("Company"))
End While
SqlReader.Close()
SqlConnection1.Close()
IveFilledCompanys = 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.DataBindings.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?
on a winform. It works but only because I am making use of a public
boolean variable called IveFilledCompanys. The code follows:
If IveFilledCompanys = False Then
SqlConnection1.Open()
Dim SqlReader As System.Data.SqlClient.SqlDataReader
SqlReader = SqlCommand1.ExecuteReader()
While SqlReader.Read
cboCompanys.Items.Add(SqlReader.Item("Company"))
End While
SqlReader.Close()
SqlConnection1.Close()
IveFilledCompanys = 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.DataBindings.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?