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. C#
  4. populating combo box on selectedindex changedevent of other combo box1

populating combo box on selectedindex changedevent of other combo box1

Scheduled Pinned Locked Moved C#
csharp
10 Posts 3 Posters 0 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.
  • M Offline
    M Offline
    monuSaini
    wrote on last edited by
    #1

    Hello EveryBody, I had two combo box (combo box1, combo box2) I had populated the combox1 using dataset (having values in display member and value member) I want to pupulate combo box2 on the selectedindexChangeEvent but I am getting System.Data.DataRowView on comboBox1.selectedvalue.tostring(); I am unable to understand why it is returning this value. And outside this event it is giving right value. working on c# (windows application) Regards, rahul saini

    V 1 Reply Last reply
    0
    • M monuSaini

      Hello EveryBody, I had two combo box (combo box1, combo box2) I had populated the combox1 using dataset (having values in display member and value member) I want to pupulate combo box2 on the selectedindexChangeEvent but I am getting System.Data.DataRowView on comboBox1.selectedvalue.tostring(); I am unable to understand why it is returning this value. And outside this event it is giving right value. working on c# (windows application) Regards, rahul saini

      V Offline
      V Offline
      valerian precop
      wrote on last edited by
      #2

      It would be more helpful if you could put some code also...

      Just call me Valy... :)

      M 1 Reply Last reply
      0
      • V valerian precop

        It would be more helpful if you could put some code also...

        Just call me Valy... :)

        M Offline
        M Offline
        monuSaini
        wrote on last edited by
        #3

        Hi Valy, Here is the code for populating the combo box1 string sqlQuery = "select * from category "; SqlConnection objConnection = new SqlConnection(objFunctions.strConn); objConnection.Open(); SqlDataAdapter adapter = new SqlDataAdapter(sqlQuery, objConnection); DataSet ds = new DataSet(); adapter.Fill(ds); DataTable objDataTable = ds.Tables[0]; cmb_category.DataSource = objDataTable; cmb_category.DisplayMember = "categoryName"; cmb_category.ValueMember = "categoryId"; objConnection.Close(); AND on selectedIndexChangeEvent I m populating combo box using comboBox1.selectedValue but it is returning System.Data.DataRowView Regards, rahul saini

        N V 2 Replies Last reply
        0
        • M monuSaini

          Hi Valy, Here is the code for populating the combo box1 string sqlQuery = "select * from category "; SqlConnection objConnection = new SqlConnection(objFunctions.strConn); objConnection.Open(); SqlDataAdapter adapter = new SqlDataAdapter(sqlQuery, objConnection); DataSet ds = new DataSet(); adapter.Fill(ds); DataTable objDataTable = ds.Tables[0]; cmb_category.DataSource = objDataTable; cmb_category.DisplayMember = "categoryName"; cmb_category.ValueMember = "categoryId"; objConnection.Close(); AND on selectedIndexChangeEvent I m populating combo box using comboBox1.selectedValue but it is returning System.Data.DataRowView Regards, rahul saini

          N Offline
          N Offline
          Nisar Inamdar
          wrote on last edited by
          #4

          hi instead of using combobox1.selectedvalue you have to use combobox1.selectedindex.tostring() Nisar Inamdar.

          M 1 Reply Last reply
          0
          • N Nisar Inamdar

            hi instead of using combobox1.selectedvalue you have to use combobox1.selectedindex.tostring() Nisar Inamdar.

            M Offline
            M Offline
            monuSaini
            wrote on last edited by
            #5

            Hi Nisar, It is giving the index value but i want the selectedItemValue for populating comboBox2 with help of the value i had to retrieve value from database Regards, rahul saini

            N 1 Reply Last reply
            0
            • M monuSaini

              Hi Nisar, It is giving the index value but i want the selectedItemValue for populating comboBox2 with help of the value i had to retrieve value from database Regards, rahul saini

              N Offline
              N Offline
              Nisar Inamdar
              wrote on last edited by
              #6

              Hi Rahul, on combo1.selectedIndexEvent use query " Select fieldName from tablname where fieldname="+combo1.Selectedindex.toString()"; Nisar Inamdar.

              M 1 Reply Last reply
              0
              • M monuSaini

                Hi Valy, Here is the code for populating the combo box1 string sqlQuery = "select * from category "; SqlConnection objConnection = new SqlConnection(objFunctions.strConn); objConnection.Open(); SqlDataAdapter adapter = new SqlDataAdapter(sqlQuery, objConnection); DataSet ds = new DataSet(); adapter.Fill(ds); DataTable objDataTable = ds.Tables[0]; cmb_category.DataSource = objDataTable; cmb_category.DisplayMember = "categoryName"; cmb_category.ValueMember = "categoryId"; objConnection.Close(); AND on selectedIndexChangeEvent I m populating combo box using comboBox1.selectedValue but it is returning System.Data.DataRowView Regards, rahul saini

                V Offline
                V Offline
                valerian precop
                wrote on last edited by
                #7

                I think I got it. You must use ((DataRowView)comboBox1.SelectedItem).Row["categoryId"].ToString() instead of comboBox1.selectedValue

                Just call me Valy... :)

                M 1 Reply Last reply
                0
                • N Nisar Inamdar

                  Hi Rahul, on combo1.selectedIndexEvent use query " Select fieldName from tablname where fieldname="+combo1.Selectedindex.toString()"; Nisar Inamdar.

                  M Offline
                  M Offline
                  monuSaini
                  wrote on last edited by
                  #8

                  Yes I using the same query but as on populating comboBox1 i get category1 its value is 23 category2 its value is 32 but when on selecting category1 its index value is 0 and that is wat comboBox1.selectIndex is giving and i want its value that is 23. Regards, rahul saini

                  N 1 Reply Last reply
                  0
                  • V valerian precop

                    I think I got it. You must use ((DataRowView)comboBox1.SelectedItem).Row["categoryId"].ToString() instead of comboBox1.selectedValue

                    Just call me Valy... :)

                    M Offline
                    M Offline
                    monuSaini
                    wrote on last edited by
                    #9

                    Hi Valy , Thanks, Its working fine. Regards, rahul saini

                    1 Reply Last reply
                    0
                    • M monuSaini

                      Yes I using the same query but as on populating comboBox1 i get category1 its value is 23 category2 its value is 32 but when on selecting category1 its index value is 0 and that is wat comboBox1.selectIndex is giving and i want its value that is 23. Regards, rahul saini

                      N Offline
                      N Offline
                      Nisar Inamdar
                      wrote on last edited by
                      #10

                      ;)hi rahul, Try combo1.SelectedItem.ToString(); It will be worked. Nisar Inamdar.

                      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