How can add "All" as a new item to the combobox that populated with datasource (VB.Net)

Answered How can add "All" as a new item to the combobox that populated with datasource (VB.Net)

  • Thursday, August 02, 2012 12:19 PM
     
     

    Hi every one

    Can u help me for add "All" as a new item to the combobox that populated with datasource (VB.Net)?

    my combobax populeted with linq to sql and i thin

    Thanks in advance

All Replies

  • Thursday, August 02, 2012 12:22 PM
     
     
    What is dataSource? DataTable?

    Mitja

  • Saturday, August 04, 2012 1:27 AM
     
     Answered Has Code

    -------------------------------- The answer of  my question! ----------------------------------

    I have a table with 3 column that one of them, named Remark (table name is Supply_list and columns are Pos, Qty and Remark in SQL). this Table Contain some repeated data in "Remark" column that i wanted to use these data grouped into a combobox, for filtering a datagridview. but i wanted to add "All" such as new item to my retrieved items.

    1- use table from SQL with LINQ to SQL.

    2- and the code in VB.Net

    Class Form1 Dim db As New ReLinqDataContext(My.Settings.LiberConnectionString) Dim AllString() As String = {"ALL"} Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load Dim query2 = (From sta2 In db.Supply_Lists Group By sta2.Remark Into Any() _ Select Remark) Dim AllString2 = AllString.Union(query2).ToList ComboBox1.DataSource = AllString2 For Each h In query2 Console.WriteLine(h) Next Console.ReadLine() End Sub

    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged If Me.ComboBox1.Text <> "ALL" Then Dim query1 = From sta In db.Supply_Lists _ Select Pos = sta.Assembly_Name, sta.Qty, sta.Remark _ Where Remark = Me.ComboBox1.Text Me.DataGridView1.DataSource = query1 Else Dim query1 = From sta In db.Supply_Lists _ Select Pos = sta.Assembly_Name, sta.Qty, sta.Remark Me.DataGridView1.DataSource = query1 End If End Sub End Class

    I hope this example be helpful for you


    • Edited by R. Salehi Saturday, August 04, 2012 1:32 AM
    • Marked As Answer by R. Salehi Saturday, August 04, 2012 1:40 AM
    •  
  • Tuesday, August 07, 2012 6:10 AM
    Moderator
     
     

    Hi R. Salehi,

    Thanks for sharing the solution. It will be helpful to other community members who has similar questions.

    Have a nice day!


    Chester Hong
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.