malanois
asked on
Update DataGrid
I am filling a datagrid on the form load.
I am also filling a combo box, that has links to the datagrid.
As the user clicks the combo box i want to filter the datagrid to show only the rows that pertain to the combo.
I am having the problem with updating and the filtering of the datagrid.
Private Sub ComboBox1_SelectedIndexCha nged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb_feature.SelectedIndexC hanged
Dim t as string
t = cmb_feature.Text.ToString
<<<<<<-------------------- ---------- ---------- ---------- ------How do i update and <<<<<<<<<<<<<<<----------- ---------- ---------- ---------- ---------- --------fi lter the datagrid
Me.Db_FC_Datagrid.Tables(" Feature Bill").DefaultView.RowFilt er = t
End Sub
I am also filling a combo box, that has links to the datagrid.
As the user clicks the combo box i want to filter the datagrid to show only the rows that pertain to the combo.
I am having the problem with updating and the filtering of the datagrid.
Private Sub ComboBox1_SelectedIndexCha
Dim t as string
t = cmb_feature.Text.ToString
<<<<<<--------------------
Me.Db_FC_Datagrid.Tables("
End Sub
if you use a valuemember 'like an ID" in your combobox which corresponts to your datagrid column
then use something like
Me.Db_FC_Datagrid.Tables(" Feature Bill").DefaultView.RowFilt er = "yourID = " & combobox1.selectedvalue
then use something like
Me.Db_FC_Datagrid.Tables("
ASKER
does that automatically update the datafrid if it has already been filled?
yes it should, if ofcourse the datagrids datasource = is the same datasource you used to filter the records
ASKER
OK, I have a little problem though:
Here is my select statement
SELECT DISTINCT T_CONFIG_GUIDES_CB.Feature Code + ' / ' + T_CONFIG_GUIDES_FCBASE.Tit le AS combined FROM (T_CONFIG_GUIDES_FCBASE INNER JOIN T_CONFIG_GUIDES_CB ON T_CONFIG_GUIDES_FCBASE.Fea tureCode = T_CONFIG_GUIDES_CB.Feature Code)
as you can see i am combining featurecode and title as combined.
on the selectedindexchanged of the combo how can I just get the feature code out of it, to macth the other information.
Here is my select statement
SELECT DISTINCT T_CONFIG_GUIDES_CB.Feature
as you can see i am combining featurecode and title as combined.
on the selectedindexchanged of the combo how can I just get the feature code out of it, to macth the other information.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
something like
Me.Db_FC_Datagrid.Tables(" Feature Bill").DefaultView.RowFilt er = "featurecode = '" & FCode(combobox1.text) & "'"
Private Function FCode(ByVal fc As String) As String
Dim g As String = fc.Substring(0, fc.IndexOf("/")).TrimEnd
Return g
End Function
Me.Db_FC_Datagrid.Tables("
Private Function FCode(ByVal fc As String) As String
Dim g As String = fc.Substring(0, fc.IndexOf("/")).TrimEnd
Return g
End Function
ASKER
Me.Db_FC_Datagrid.DataSour ce = dv <-----------------It is giving an error, read Only
Dim dv As New DataView
dv = yourdataset.Tables("Featur
dv.RowFilter = "ColumnName = '" & sender.SelectedValue.ToStr
Me.Db_FC_Datagrid.DataSour
ASKER
If I try
Me.Db_FC_Datagrid.DataSour ce = dv I get DataDource is not a member
If I try
Me.Db_FC_Datagrid.T_CONFIG _GUIDES = dv
I get read only
I changed the dv as new dataview
Me.Db_FC_Datagrid.DataSour
If I try
Me.Db_FC_Datagrid.T_CONFIG
I get read only
I changed the dv as new dataview
What type of object is Db_FC_Datagrid?
Is it a Dataset or Datagrid?
if it is a dataset the code would look like this:
Dim dv As New DataView
dv = Db_FC_Datagrid.Tables("Fea ture Bill").DefaultView
dv.RowFilter = "ColumnName = '" & sender.SelectedValue.ToStr ing & "'"
Me.YourDataGrid.DataSource = dv
or if you are using the Text Property of you combobox
Dim dv As New DataView
dv = Db_FC_Datagrid.Tables("Fea ture Bill").DefaultView
dv.RowFilter = "ColumnName = '" & sender.Text.ToString & "'"
Me.YourDataGrid.DataSource = dv
if it is a dataset the code would look like this:
Dim dv As New DataView
dv = Db_FC_Datagrid.Tables("Fea
dv.RowFilter = "ColumnName = '" & sender.SelectedValue.ToStr
Me.YourDataGrid.DataSource
or if you are using the Text Property of you combobox
Dim dv As New DataView
dv = Db_FC_Datagrid.Tables("Fea
dv.RowFilter = "ColumnName = '" & sender.Text.ToString & "'"
Me.YourDataGrid.DataSource
ASKER
I got it,
STIMPY YOU I D I O T
i was not putting the correct datagrid name in.
THANKS SO MUCH !!!!!!!!!
STIMPY YOU I D I O T
i was not putting the correct datagrid name in.
THANKS SO MUCH !!!!!!!!!
Private Sub ComboBox1_SelectedIndexCha
Me.Db_FC_Datagrid.Tables("
End Sub
yourname should ofcourse be the column name you want to filter on