Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtering a DataView

Status
Not open for further replies.

christheprogrammer

Programmer
Jul 10, 2000
258
CA
Good Mornin'

I have a dataview bound to table 0 of a dataset which in turn was populated by running a simple query on SQL Server. The result set is set of species names of fish. I want to display the dataview in a listbox, but I want to filter out all items containing a left or right paren. I am using a Dataview so that I can also sort the items.
Here is my code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dv As DataView
If Not IsPostBack Then
appDataComponent.fillDataSet(speciesDataSet)
dv = New DataView(speciesDataSet.Tables(0))
dv.Sort = "SPECIES_COMMON_NAME, SPECIES_CODE ASC"
speciesListBox.DataSource = dv
speciesListBox.DataTextField = "SPECIES_COMMON_NAME"
speciesListBox.DataValueField = "SPECIES_CODE"
speciesListBox.DataBind()
End If
End Sub


Which produces a listbox containing something like the follwing:

(GENUS)
(GENUS)
(SUB-FAMILY)
ABYSSAL SKATE
ABYSSAL SNAILFISH
ANCHOVIES (FAMILY)
...


Anyways, I don't want any of the entries containing the parens to appear in the listbox: (GENUS), (SUB-FAMILY), ANCHOVIES (FAMILY)

How do I filter this list?
TIA Chris says: "It's time for a beer."
 
Figured it out:

For Each row In speciesDataSet.Tables(0).Rows
If row("SPECIES_COMMON_NAME").ToString Like "*(*" Then
row.Delete()
End If
Next
speciesDataSet.AcceptChanges()


goes after dataset is loaded and before creating the new dataview from the dataset.. Now, how do I give myself a star? hehe Chris says: "It's time for a beer."
 
Hi Chris

I'm working with ASP.NET listboxes that I need to sort. In your problem, you refered to being able to sort them if you put them in a DataSet. I'm not familiar with DataSets. I tried putting the ListBox.DataSource into a DataView so I could sort it, but then I don't have a 'column name' to sort on. Can you give me some tips on an easy way to sort the listboxes.

Thanks,

Judy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top