how to bind a combo box with a datalist that is binded with a datagrid

Discussion in 'Software' started by allredndizzy, Jun 8, 2005.

  1. allredndizzy

    allredndizzy Private E-2

    Hello! i just want to ask if it is possible to bind a combo box with a datalist that is already binded with a datagrid... the datalist and the datagrid are working ok.. when i click on a field in the datalist...the datagrid produces the data in the tables that i binded with the datalist... but i also want to bind that same datalist with a combo box... when i run the program, the datalist automatically has something on it (the ones i want it to show) but what i want to know is, how can i control the data that's going to show on the datalist... i hope i'm making sense here.... my combo box automatically produces a list of dates when i click the dropdown...while my datalist automatically produces a list of all the companies...what i want is.. when i click on a certain date in my combo box, that's the only time my datalist will show some data (companies) and those companies that will be shown will depend on the date in the combo box..meaning not all companies will be shown...only those that apply to that certain date that i selected in my combo box... please help!
     
  2. Kodo

    Kodo SNATCHSQUATCH

    Not sure I completely follow you, but that's ok because once you have your dataset or preferably a datatable in memory, you can go to town on it. You can bind that set or table to anything you want when ever you want. If you select dates in your cbox then what I would do is just do a datatable.select() and pass your filter in and bind your datatable to your datalist.
     
  3. allredndizzy

    allredndizzy Private E-2

    is the datatable.select() you are talking about a function? i'm sorry but i'm a newbie.. i don't exactly know how to do this.. would u mind explaining it further?
     
  4. Kodo

    Kodo SNATCHSQUATCH

    you can read my blog to get a another view of it..
    http://spaces.msn.com/members/kodosan/Blog/cns!1pGDzWSnMimb_jE5ra_RAbvQ!241.entry

    .Select() is a function that selects ALL of your records in the datatable specified.
    if you did something like .Select("FirstName='foobar'")

    then it would select all rows where the field "FirstName" = foobar

    I wish I had more time to explain... gotta run.. sorry.
     
  5. Kodo

    Kodo SNATCHSQUATCH

    I'm back with a better example and sample code

    This code would load up your data. place in event that you wish to fire to load the combobox up.
    Code:
           Dim SQL As String = "[color=Sienna]Select Statement here[/color]"
                  Dim DT As New DataTable("[color=White]Assign Your Database Table Name Here[/color]")
                  Dim MySQL As New SqlClient.SqlCommand(SQL, Conn)
                  Conn.Open()
                  Dim DA As New SqlClient.SqlDataAdapter(MySQL)
                  DA.Fill(DT)
          
                  Me.ComboBox1.DataSource = DT
                  Me.ComboBox1.DisplayMember = "[color=Blue]FieldNameToBindToForDisplay[/color]"
                  Me.ComboBox1.ValueMember = "[color=Red]FileNameToBindToForValue[/color]"
        
        

    EXAMPLE OF MY DATABASE WITH STATEMENTS SO YOU CAN SEE WHAT I"M TALKING ABOUT

    Code:
        		Dim SQL As String = "[color=Sienna]Select * from BHO[/color]"
        		Dim DT As New DataTable("[color=White]BHO[/color]")
        		Dim MySQL As New SqlClient.SqlCommand(SQL, Conn)
        		Conn.Open()
        		Dim DA As New SqlClient.SqlDataAdapter(MySQL)
        		DA.Fill(DT)
        
        		Me.ComboBox1.DataSource = DT
        		Me.ComboBox1.DisplayMember = "[color=Blue]Cat[/color]"
        		Me.ComboBox1.ValueMember = "[color=Red]ID[/color]"
        

    This is the code you use when you select an item from the list

    Code:
        
        		Dim drv As DataRowView = Me.ComboBox1.SelectedItem
        		Dim strFilter As String = drv("[color=DarkSlateBlue]FIELDNAMEHERE[/color]")
        		Dim DT As DataTable
        		DT = ComboBox1.DataSource
        		Dim DV As New DataView(DT)
        		DV.RowFilter = "[color=Magenta]DATABASEFIELDNAME[/color]='" & strFilter & "' "
        		Me.DataGrid1.DataSource = DV
        
    My Example with actual field names etc

    Code:
        		Dim drv As DataRowView = Me.ComboBox1.SelectedItem
        		Dim strFilter As String = drv("[color=DarkSlateBlue]Cat[/color]")
        		Dim DT As DataTable
        		DT = ComboBox1.DataSource
        		Dim DV As New DataView(DT)
        		DV.RowFilter = "[color=Magenta]Cat[/color]='" & strFilter & "' "
        		Me.DataGrid1.DataSource = DV
        
    Datatables are what is loaded into a dataset so if you only need one table then a datatable is the way to go. If you need to load more than one table or you need some of the more advanced features of a dataset then obviously use a dataset.

    I color coded matching items in the examples so you can see what matches up.
    Hope this helps.

    [edit]
    make sure you use TRY CATCH with this


    try

    [code here]

    catch ex as exception
    'do error response event
    end try
     
  6. allredndizzy

    allredndizzy Private E-2

    i'm sorry..but looks like we have aproblem here... im using visual basic ver 6.0 and my database is only MS Access.. sorry i didn't say it in the beginning.. i can't understand the codes u wrote..i'm sorry..anyway do u know how to do it using vb6 and ms access? and another question... when i run my program, my datalist already has something on it.. d records on my databoundcolumn.. but i don't want them to show at start-up... i want them to show only when i click a certain button..is it possible? can u show me how? thanks! u r really nice ;)
     
  7. Kodo

    Kodo SNATCHSQUATCH

    Bummer.. why are you using VB6? School?
    Anyway, I don't have my VB6 IDE handy, so I would suggest you look up ADODC object for VB6. It will make your life a bit easier.
     
  8. allredndizzy

    allredndizzy Private E-2

    no i'm doing this for the company where i am a trainee (a requirement in our school before i can take my thesis) but yep i'm still in school and the reason why using it is because it's the only database programming language that i can manipulate so far...sucks i know but don't worry i will study other languages as well..i don't want to be stuck here forever hehe! anyway thank you for replying to my thread..it is greatly appreciated! godspeed!
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds