Solved

populate a datagrid according to a combo box choice in vb.net

Posted on 2004-09-13
8
492 Views
Last Modified: 2006-11-17
i have created a datagrid in vb.net that is populated by data contained in a mysql database. On the interface,the user must select an item from a combo box , the datagrid will be populated with data of that type. For instance, the user selects option1 the datagrid will be populated with data of type option 1.
i appreciated any help
0
Comment
Question by:webusername
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 10

Expert Comment

by:123654789987
Comment Utility
What are these options that u are taking about? is the combobox populated from a datatable? I need more info
0
 
LVL 19

Expert Comment

by:arif_eqbal
Comment Utility
If it is VB.NET then...
on SelectedIndexChanged event of the ComboBox populate your grid, if it is to be populated from database then open your connection etc. and bind the grid.

If you are using ASP.NET then....
set the AutoPostBack Property of the comboBox to True, then do as above..


0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 500 total points
Comment Utility
Hi webusername,

There are several ways to do this for instance use a dataview and rowfilter method (ds is the dataset)
dim dv as new dataview = ds.tables(0).defaultview
yourdatagrid.datasource =  dv

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        dv.rowfilter = "youroption = " & ComboBox1.Text
' or use the selectedvalue combobox1.selectedvalue or selectedtext
    End Sub

0
 

Author Comment

by:webusername
Comment Utility
Actually the combo box is not populated from the database, it is only the datagrid that is populated from the database. the combo box contains items like option 1,option 2, option 3. if the user selects option1 , the database will be populated by data of type option 1 , this is done the statement : select * from tableoption where choice =(user choice from combo)
as you see i dont know how to write a statement that gets the value selected by the user in the combo box
thanks
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 25

Expert Comment

by:RonaldBiemans
Comment Utility
Hi webusername,

well you are actually almost there

"select * from tableoption where choice = " & combobox1.text
0
 

Author Comment

by:webusername
Comment Utility
Comment from RonaldBiemans  feedback
Date: 09/14/2004 01:49AM PDT
 Comment  


Hi webusername,

well you are actually almost there

"select * from tableoption where choice = " & combobox1.text

when you put combobox1.text , does it mean that it would take the value that is selected in combo box
thanks
0
 
LVL 25

Expert Comment

by:RonaldBiemans
Comment Utility
Yes
0
 
LVL 10

Expert Comment

by:123654789987
Comment Utility
1. Get all the data from the database in DataTable1

Then filter data from the datatable using a select option
In the selected Index Changed method

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
 strExpr = "choice = option1"  //Forming a expression

Dim datatable2 as DataTable
dataRow2 = new DataTable

Dim dataRow2 as DataRow

  dataRow2  =  dataRow2.NewRow();
    ' Use the Select method to find all rows matching the filter.
  dataRow2 = _
        DataTable1.Select( strExpr, strSort, DataViewRowState.Added )
    End Sub

Then set
datagrid.DataSource = datatable2

2. For each index change of the combo box go to the database to get the value

string cString = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer";
      SqlConnection myConnection = new SqlConnection(cString);
              myConnection.Open();
      SqlCommand myCommand = new SqlCommand("SELECT * FROM Suppliers where choice = ?",
      myConnection);
      myCommand.CommandType = CommandType.Text;
      myCommand.Paramters.Add("param1",string, "option1");
      ds = myCommand.ExecuteDataSet();
       
DataGrid.DataSource = ds.Tables[0]


         

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now