filtering a datagrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Once again, I'm stuck.

I want to view a table using a DataGrid. I'd like to fiter that view by
criteria on various fields.

So far, I've created a DataAdapter, generated a DataSet and used that
DataSet as the DataSource for a DataGrid. I put a "fill" in my open form
event.
Me.OleDbDataAdapter1.Fill(DataSet11)

Then I tried a select statement:
Me.DataSet11.Company.Select("ID=3", "ID", DataViewRowState.CurrentRows)

"Company" is the one and only table I selected when configuring the
DataAdapter.

The entire dataset shows up in my DataGrid. I can't seem to get it to filter.

Can anyone help?

Art
 
Try using a dataview to filter the events. Then bind the dataview to the
datasource. Set the DataView.Rowfilter property to get your subset.

Chris
 
Chris,

I will need to select criteria during run time. That is, I'll pick
something from a ComboBox and I'll want to make my DataGrid show me the
appropriate records. Can a DataView do this? I did read a little on it and
it sounded like it was something that had to be set up ahead of time.

Thanks for your help.

Art
 
nope. it's all runtime. This is an example that I wrote in here but didn't
test but the idea will be there

Me.OleDbDataAdapter1.Fill(DataSet11)
DataSet11.Table(0).DefaultView.RowFilter = "ColumnName = FilterValue"
DataGrid1.DataSource = DataSet11.Table(0).DefaultView

That should work. The RowFilter property is basically a where clause of a
SQL statment. You can create a DataView object instead of using the
defaultview from the datatable if you want.

Me.OleDbDataAdapter1.Fill(DataSet11)
Dim DV as DataView
DV = DataSet11.Table(0).DefaultView
DV.RowFilter = .RowFilter = "ColumnName = FilterValue"
DataGrid1.DataSource = DV

Hope it helps
Chris
 
Chris,

Works GREAT!! Thanks!

Art

Chris said:
nope. it's all runtime. This is an example that I wrote in here but didn't
test but the idea will be there

Me.OleDbDataAdapter1.Fill(DataSet11)
DataSet11.Table(0).DefaultView.RowFilter = "ColumnName = FilterValue"
DataGrid1.DataSource = DataSet11.Table(0).DefaultView

That should work. The RowFilter property is basically a where clause of a
SQL statment. You can create a DataView object instead of using the
defaultview from the datatable if you want.

Me.OleDbDataAdapter1.Fill(DataSet11)
Dim DV as DataView
DV = DataSet11.Table(0).DefaultView
DV.RowFilter = .RowFilter = "ColumnName = FilterValue"
DataGrid1.DataSource = DV

Hope it helps
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top