Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. How to add a new row in combobox , after binding it using LINQ. in vb.net [modified]

How to add a new row in combobox , after binding it using LINQ. in vb.net [modified]

Scheduled Pinned Locked Moved LINQ
csharpdatabasewpfwcf
4 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nilish
    wrote on last edited by
    #1

    Public Function ReturnProjectStatus() As Object
    Dim Baseclassobject As BaseClassDataContext = Nothing
    Try
    Baseclassobject = New BaseClassDataContext(BLLmdlCommon.strConfiguration)
    Dim query = From p In Baseclassobject.GetTable(Of CP_PRJ_ProjectStatus)() Select p
    Return query
    Catch ex As Exception

        End Try
    End Function
    

    private sub abc()
    cmbStatus.DisplayMember = "name"
    cmbStatus.ValueMember = "ID"
    Dim query = ReturnProjectStatus()

    combobox1.datasource = query

    'Now I want to add a new item in combobox after binding , at first index.How should i do it
    end sub</pre>

    modified on Wednesday, August 20, 2008 3:13 PM

    H 1 Reply Last reply
    0
    • N Nilish

      Public Function ReturnProjectStatus() As Object
      Dim Baseclassobject As BaseClassDataContext = Nothing
      Try
      Baseclassobject = New BaseClassDataContext(BLLmdlCommon.strConfiguration)
      Dim query = From p In Baseclassobject.GetTable(Of CP_PRJ_ProjectStatus)() Select p
      Return query
      Catch ex As Exception

          End Try
      End Function
      

      private sub abc()
      cmbStatus.DisplayMember = "name"
      cmbStatus.ValueMember = "ID"
      Dim query = ReturnProjectStatus()

      combobox1.datasource = query

      'Now I want to add a new item in combobox after binding , at first index.How should i do it
      end sub</pre>

      modified on Wednesday, August 20, 2008 3:13 PM

      H Offline
      H Offline
      Howard Richards
      wrote on last edited by
      #2

      Try adding the 'static' items first, then use AppendDataBoundItems = true

      'Howard

      N 1 Reply Last reply
      0
      • H Howard Richards

        Try adding the 'static' items first, then use AppendDataBoundItems = true

        'Howard

        N Offline
        N Offline
        Nilish
        wrote on last edited by
        #3

        I am using windows . Before switched on to LINQ , I was doing like , i fetched the datatable from combo box datasource , Then adding a new row in that table , finally inserting the data in that row , and placing that row in the datatable , and was giving the data source to combo box. In this way i was attaching the items in combo box manually. But this time , using the LINQ , i don't want to use the datatable. Please help.

        modified on Thursday, August 21, 2008 9:43 AM

        H 1 Reply Last reply
        0
        • N Nilish

          I am using windows . Before switched on to LINQ , I was doing like , i fetched the datatable from combo box datasource , Then adding a new row in that table , finally inserting the data in that row , and placing that row in the datatable , and was giving the data source to combo box. In this way i was attaching the items in combo box manually. But this time , using the LINQ , i don't want to use the datatable. Please help.

          modified on Thursday, August 21, 2008 9:43 AM

          H Offline
          H Offline
          Howard Richards
          wrote on last edited by
          #4

          To be able to insert in the code you need to know the type of object in your list. Your original query returns IEnumerable(of CP_PRJ_ProjectStatus) so you'd have to insert a new CP_PRJ_ProjectStatus entry into that (which you probably don't want to do). Secondly the query is returning the whole table when only two values are needed. You could create your own structure or class to hold the ID,Name values and then insert one at the top, in the example below I've used the generic KeyValuePair class since it's there already. I've put ID into Key and Name into Value.

          Public Function ReturnProjectStatus() As List(Of KeyValuePair(of String, String))
          Dim Baseclassobject As BaseClassDataContext = Nothing
          Try
          Baseclassobject = New BaseClassDataContext(BLLmdlCommon.strConfiguration)

              Dim query = From p In Baseclassobject.GetTable(Of CP\_PRJ\_ProjectStatus)() \_
                          Select New KeyValuePair(of String, string)(p.ID, p.Name) \_
              Return query.ToList()
          
           Catch ex As Exception
           End Try
          

          End Function

          Private Sub abc()
          cmbStatus.DisplayMember = "name"
          cmbStatus.ValueMember = "ID"
          Dim query = ReturnProjectStatus()
          'Insert new value at top
          query.Insert(0, New KeyValuePair(of string, string)("ID","Value")
          combobox1.datasource = query
          End Sub

          'Howard

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups