[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Update DataGrid

Posted on 2004-09-27
13
Medium Priority
?
280 Views
Last Modified: 2010-04-23
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_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb_feature.SelectedIndexChanged
Dim t as string
t = cmb_feature.Text.ToString

                         <<<<<<--------------------------------------------------------How do i update and  <<<<<<<<<<<<<<<-----------------------------------------------------------filter the datagrid

        Me.Db_FC_Datagrid.Tables("Feature Bill").DefaultView.RowFilter = t


    End Sub

0
Comment
Question by:malanois
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 3
13 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12159986
it should be something like this

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb_feature.SelectedIndexChanged

        Me.Db_FC_Datagrid.Tables("Feature Bill").DefaultView.RowFilter = "yourname = '" & combobox1.text & "'"

    End Sub

yourname should ofcourse be the column name you want to filter on

0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12160003
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.RowFilter = "yourID = " & combobox1.selectedvalue
0
 

Author Comment

by:malanois
ID: 12160073
does that automatically update the datafrid if it has already been filled?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12160138
yes it should, if ofcourse the datagrids datasource = is the same datasource you used to filter the records

0
 

Author Comment

by:malanois
ID: 12160485
OK,  I have a little problem though:

Here is my select statement

SELECT DISTINCT T_CONFIG_GUIDES_CB.FeatureCode + '    /    ' + T_CONFIG_GUIDES_FCBASE.Title AS combined FROM (T_CONFIG_GUIDES_FCBASE INNER JOIN T_CONFIG_GUIDES_CB ON T_CONFIG_GUIDES_FCBASE.FeatureCode = T_CONFIG_GUIDES_CB.FeatureCode)

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.

0
 
LVL 8

Accepted Solution

by:
wguerram earned 2000 total points
ID: 12160510
You have to use the DataTable or DataSet instead of the Datagrid.Tables

Private Sub cmb_feature_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb_feature.SelectedIndexChanged

        Dim dv As DataView
        dv = yourdataset.Tables("Feature Bill").DefaultView
        dv.RowFilter = "ColumnName = '" & sender.SelectedValue.ToString & "'"
        Me.Db_FC_Datagrid.DataSource = dv

    End Sub

I am enclosing the filter with single '

dv.RowFilter = "ColumnName = '" & sender.SelectedValue.ToString & "'"

If the value is character type, if numeric you don't need them.

And the grid is refreshed automatically.
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12160624
something like

 Me.Db_FC_Datagrid.Tables("Feature Bill").DefaultView.RowFilter = "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
0
 

Author Comment

by:malanois
ID: 12161074
Me.Db_FC_Datagrid.DataSource = dv   <-----------------It is giving an error, read Only
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12161150

Dim dv As New DataView
dv = yourdataset.Tables("Feature Bill").DefaultView
dv.RowFilter = "ColumnName = '" & sender.SelectedValue.ToString & "'"
Me.Db_FC_Datagrid.DataSource = dv
0
 

Author Comment

by:malanois
ID: 12161471
If I try
Me.Db_FC_Datagrid.DataSource = 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
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12161637
What type of object is Db_FC_Datagrid?
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12161900
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("Feature Bill").DefaultView
dv.RowFilter = "ColumnName = '" & sender.SelectedValue.ToString & "'"
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("Feature Bill").DefaultView
dv.RowFilter = "ColumnName = '" & sender.Text.ToString & "'"
Me.YourDataGrid.DataSource = dv
0
 

Author Comment

by:malanois
ID: 12162008
I got it,

STIMPY YOU I D I O T

i was not putting the correct datagrid name in.


THANKS SO MUCH !!!!!!!!!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question