> dt is the data table of items.
location.datasource = SELECT DISTINCT location FROM dt
contract.datasource = SELECT DISTINCT contract FROM dt
To filter a series of stuff in a DataTable, you can do this:
dt.DefaultView.RowFilter = "any where clause without the word where"
However, I think your problem is different. I think you need 3 DataTables:
1. the records for location
2. the records for contract
3. the records for your user to interact with on your form.
Make a stored procedure in your database like this:
CREATE PROCEDURE dbo.GetMyStuff (
@param INT -- or whatever, if you need parameters
) AS
SELECT DISTINCT stuff for location FROM wherever
SELECT DISTINCT stuff for contract FROM wherever
SELECT stuff for your form FROM wherever WHERE whatever
GO
Then you set up a SqlDataAdapter to call your stored procedure and you use a
DataSet instead of a DataTable:
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
....
' [Jedi] you're storing the connect string in the .config file, aren't you.
Dim cnstr As String = _
ConfigurationSettings.AppSettings("connectionStrin g")
Dim cn As New SqlConnection(cnstr)
Dim ds As New DataSet()
Dim da As New SqlDataAdapter("dbo.GetMyStuff", cn)
da.Fill(ds)
' Now your DataSet has three DataTables in it:
' ds.Tables(0)... ds.Tables(1)... ds.Tables(2)
' Which one is which is controlled by the order of the select
' statements inside the stored procedure:
' ds.Tables(0) is your location stuff
' ds.Tables(1) is your contract stuff
' ds.Tables(2) is your stuff for other bound things on your form
' If you need the three DataTables to have structured relationships
' inside the DataSet, you can create a DataRelation object that points
' to the parent column in one DataTable and the child column in the other.
' So now your list bindings are nicer:
location.DataSource = ds.Tables(0)
contract.DataSource = ds.Tables(1)
' etc...
For your filtering needs, each of those three DataTables has a DefaultView
property which represents a DataView object. That property has a RowFilter
property.
For more info, press CTRL+ALT+J and search the object browser for DataView
--
Peace & happy computing,
Mike Labosh, MCSD
"Mr. McKittrick, after very careful consideration, I have
come to the conclusion that this new system SUCKS."
-- General Barringer, "War Games"