Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 03, 2012 08:55 AM by Qin Dian Tang - MSFT
May 01, 2012 06:25 PM|LINK
I am using a datagrid and want to change the view interactively in the app.
I am using a combobox to select a state, and want to filter the dataset which contains every state.
But this code does not empty the existing contents from the datagrid and fill it with the new view results.
Here is the code -- the statement that intializes mydataview seems to be returning a reasonable number of rows per request.
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim str As String
Dim MyCommand As OleDb.OleDbDataAdapter = OleDbDataAdapter1
Dim DS As New db2DataSet
str = "State = " + ComboBox1.Text
Dim mydataview As New DataView(DS.Tables("counties"), str, "SORT = DIVORCED", DataViewRowState.CurrentRows)
Me.DGDetails.DataSource = "" 'Me.DGDetails is the current datagrid. This line is intended to empty the datagrid.
Me.DGDetails.DataSource = mydataview ' This line should fill the datagrid with the filtered results of the mydataview instance.
I would welcome a link to an example that uses this method, or a parameterized query to accomplish the same thing. I am coding in VB2010 and haven't upgraded the datagrid to a datagridview for several reasons not relevant here. Thanks for any help.
May 01, 2012 06:36 PM|LINK
You need to bind data after Ading new data in datasource.
May 01, 2012 07:31 PM|LINK
Thanks, but there is no "DataBind()" method for the datagrid....only a "DataBindings()" that requires some parameters, and I have gotten nowehre with that. Maybe DataBind() works with DataGridView.
I am not using the DataGridView because I started this project years ago and have too much code depending on the DataGrid to change it very easily.
May 03, 2012 08:55 AM|LINK
What you ask is winform control, this is ASP.NET forum for web controls. You can post the question to MSDN forum: