Fill Drop-Downs question

  • Thread starter Thread starter Woody Splawn
  • Start date Start date
W

Woody Splawn

I have a question about technique with regard to filling drop downs.

I have a Winform that has several different tabs and tables associated with
it. In an effort to keep the load time small I would like to not fill the
fields with lookups at form load time. I have a grid on a tab of this form
that has six fields in it that have lookups associated with them. By
lookups I mean that the dropDown in the field is populated by doing a query
on a lookup table. When is the best time to populate (fill) these lookup
fields?

I am thinking that perhaps I could do this when the grid is moved-to like in
an Enter of GotFocus event. For this particular form, the user must
explicitely place himself in edit mode by selecting a button on a toolbar.
Perhaps I could have code (say in the got focus event for the grid) that
says in effect "If the user is in edit mode, run the code that fills the
various lookup fields". I don't really know the best way to deal with this
but to finish off my supposition. If I did the above, I would like for the
code not to run if the fields have already been filled. Perhaps I should
create a global boolean variable for the form called IveAlreadyFilledGridX
and set it to true once the grid has been filled.

If anyone has any suggestions I would appreciate a response.
 
Not sure if this is what you want but I use a technique to fill a combobox
using the Enter event:

Private Sub cboCatalog_Enter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cboCatalog.Enter
Dim objDAO As New DAO(connString) 'my data access class with the ADO
commands in it.
Dim dv As DataView
Try
Cursor.Current = Cursors.WaitCursor
'remove old data
If dsMass.Tables.Contains("dtCatalog") = True Then 'dsMass is a
form level variable
dsMass.Tables.Remove("dtCatalog")
End If

strSQL = "SELECT * FROM Table1"

objDAO.FillTable(dsMass, "dtCatalog", strSQL, DBtype)
dv = (dsMass.Tables("dtCatalog")).DefaultView
dv.Sort = "descr"
With Me.cboCatalog
.DataSource = dv
.DisplayMember = "descr"
.ValueMember = "catalog"
.SelectedIndex = -1
End With
Catch ex As Exception
MessageBox.Show(ex.Message, ex.Source & " - " & ex.TargetSite.Name,
MessageBoxButtons.OK, MessageBoxIcon.Information)
Finally
objDAO = Nothing
Cursor.Current = Cursors.Default
End Try

End Sub
 
Hi Woody,

Base on my understanding, you have a form and 6 combo boxs on that form.
And you want to populate the combobox at runtime when the according
combobox got focus. There is also a button on the toolbar which indicate if
it is needed to populated. Or you have a datagrid with 6 dropdown on a form

Did I misunderstand your meaning?

Here is simple sample.
.NET Samples - Windows Forms: Data Binding
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpqstart/ht
ml/cpsmpnetsamples-windowsformsdatabinding.asp

My suggestion is that the solution is based on when the data you want to
query will vary.
If the data is persisted all the time, then you may compile it into a
datafile.
If persisted in the application lifetime, you may load it when the
application is started, if the data is too big you may need to load a part
of them first.
If the query will change every time you change the query value then I think
your solution is good.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
 
Back
Top