Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2012 Populate a Combobox from a Filtered DataGridView.

$
0
0
VS2012 Express - SQL Express - VB Coding.
============================

Good Evening. I'm certain my Inquiry has been answered numerous times before, but my search through the VBForum Threads did not reveal a solution that fits my application.

I have a combobox and DataGridView on a common userform.

I would like to populate the combobox from a column within the Filtered DataGridView.

And yet to further complicate, I would like for the returned data to be Distinct.

I can successfully populate the combobox with Distinct values from a pregenerated DataTableAdapter within the DataSet, however, the items are not filtered in sync with the DataGridView Filtering which causes the combobox to contain irrelevant data for the next level of Data Filtering.

Here's where I'm at:

Code:


DataGridView.DataSource=PrimaryDataTableBindingSource
ComboBox2.DataSource=ModifiedPrimaryDataTableBindingSource  '  This Table is only 2 columns from the Primary Table.  DataColumn1 (RequestedData) and Date Column
Combobox2.DisplayMember="DataColumn1"

' This Filters the DataGridView Fine.

PrimaryDataTableBindingSource.Filter="DataColumn2= '" & Combobox1.Text & "' and DateColumn>= '" & StartDate.Value.AddDays(-1) & "' and DateColumn<= '" & EndDate.Value & "'"

' in an effort to have the data source for Combobox2 be in sync with the PrimaryData Filtering, I tried Filtering the Modified Table with Dates.
'  With the Select Distinct statement included in the ModifiedPrimaryDataTableAdapter settings, I end up with Data from all of the rows in Combobox2,
' Regardless if it is duplicated or not.  I am Looking for unique items within the dates specified to be loaded into Combobox2.


ModifiedPrimaryDataTableBindingSource.Filter="DateColumn>= '" & StartDate.Value.AddDays(-1) & "' and DateColumn<= '" & EndDate.Value & "'"

ModifiedPrimaryDataTableAdapter.GetData()
ModifiedPrimaryDataTableAdapter.Fill(DataSet.ModifiedPrimaryData)

The End Result is that I don't have unique items populating Combobox2 between StartDate and EndDate.
How May I Populate Combobox2 from the DataGridView in a SelectDistinct manner?

Thank You !

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>