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. Visual Basic
  4. NOT ABLE TO SET THE DATASOURCE FOR THE COMBOBOX

NOT ABLE TO SET THE DATASOURCE FOR THE COMBOBOX

Scheduled Pinned Locked Moved Visual Basic
csharp
4 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
    MissionSuccess
    wrote on last edited by
    #1

    respected Gurus i m making a windows application in vb.net. here i m trying to bind a combobox from dataset. but whenever i m trying to set the datasource property of my combobox,it jumps to the selectedindexchanged event for the combo box. my code is as follows:----------------- code to populate the combobox:--------------- Public Sub populateWebtype() Try cnSQL = New SqlConnection(ConnectionString) Dim strSQL As String = "select webcode,webdesc from webmast" cnSQL.Open() cmSQL = New SqlCommand(strSQL, cnSQL) cmSQL.CommandType = CommandType.Text adpSQL = New SqlDataAdapter(cmSQL) ds = New DataSet adpSQL.Fill(ds) Dim dr As DataRow dr = ds.Tables(0).NewRow 'dr(valuemember) = "" dr("webdesc") = "--Select--" ds.Tables(0).Rows.InsertAt(dr, 0) Me.cmbWebType.DataSource = ds.Tables(0).DefaultView 'AFTER THIS LINEJUMPS TO THE SELECTEDINDEXCHANGED Me.cmbWebType.DisplayMember = "webdesc" Me.cmbWebType.ValueMember = "webcode" Me.cmbWebType.SelectedIndex = 0 cnSQL.Close() Catch ex As Exception MsgBox(ex.Message) End Try End Sub selectedindexchangedevent of combobox:----------- Private Sub cmbWebType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbWebType.SelectedIndexChanged Try Dim webcode As Integer webcode = cmbWebType.SelectedValue strSQL = "select rmdesc as RawMaterial,Micron,Density,Gsm,Quantity as Norm from webnorm,webmast,rmmast where delete_flag <> 'Y' and webnorm.webcode = webmast.webcode and webnorm.rmcode = rmmast.rmcode And webnorm.webcode = " & webcode cnSQL = New SqlConnection(ConnectionString) cnSQL.Open() cmSQL = New SqlCommand(strSQL, cnSQL) cmSQL.CommandType = CommandType.Text adpSQL = New SqlDataAdapter(cmSQL) ds = New DataSet adpSQL.Fill(ds) DataGrid1.DataSource = ds.Tables(0).DefaultView strSQL = "select distinct total_micron,total_gsm,total_quantity,sqmperkg from webnorm where delete_flag <> 'Y'And webnorm.webcode = " & webcode cmSQL = New SqlCommand(strSQL, cnSQL) Dim readSQL As SqlDataReader readSQL = cmSQL.ExecuteReader While readSQL.Read If No

    C 1 Reply Last reply
    0
    • M MissionSuccess

      respected Gurus i m making a windows application in vb.net. here i m trying to bind a combobox from dataset. but whenever i m trying to set the datasource property of my combobox,it jumps to the selectedindexchanged event for the combo box. my code is as follows:----------------- code to populate the combobox:--------------- Public Sub populateWebtype() Try cnSQL = New SqlConnection(ConnectionString) Dim strSQL As String = "select webcode,webdesc from webmast" cnSQL.Open() cmSQL = New SqlCommand(strSQL, cnSQL) cmSQL.CommandType = CommandType.Text adpSQL = New SqlDataAdapter(cmSQL) ds = New DataSet adpSQL.Fill(ds) Dim dr As DataRow dr = ds.Tables(0).NewRow 'dr(valuemember) = "" dr("webdesc") = "--Select--" ds.Tables(0).Rows.InsertAt(dr, 0) Me.cmbWebType.DataSource = ds.Tables(0).DefaultView 'AFTER THIS LINEJUMPS TO THE SELECTEDINDEXCHANGED Me.cmbWebType.DisplayMember = "webdesc" Me.cmbWebType.ValueMember = "webcode" Me.cmbWebType.SelectedIndex = 0 cnSQL.Close() Catch ex As Exception MsgBox(ex.Message) End Try End Sub selectedindexchangedevent of combobox:----------- Private Sub cmbWebType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbWebType.SelectedIndexChanged Try Dim webcode As Integer webcode = cmbWebType.SelectedValue strSQL = "select rmdesc as RawMaterial,Micron,Density,Gsm,Quantity as Norm from webnorm,webmast,rmmast where delete_flag <> 'Y' and webnorm.webcode = webmast.webcode and webnorm.rmcode = rmmast.rmcode And webnorm.webcode = " & webcode cnSQL = New SqlConnection(ConnectionString) cnSQL.Open() cmSQL = New SqlCommand(strSQL, cnSQL) cmSQL.CommandType = CommandType.Text adpSQL = New SqlDataAdapter(cmSQL) ds = New DataSet adpSQL.Fill(ds) DataGrid1.DataSource = ds.Tables(0).DefaultView strSQL = "select distinct total_micron,total_gsm,total_quantity,sqmperkg from webnorm where delete_flag <> 'Y'And webnorm.webcode = " & webcode cmSQL = New SqlCommand(strSQL, cnSQL) Dim readSQL As SqlDataReader readSQL = cmSQL.ExecuteReader While readSQL.Read If No

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Setting the datasource DOES cause an index to become selected. If you don't want that, set a flag and check it in the event.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      M 1 Reply Last reply
      0
      • C Christian Graus

        Setting the datasource DOES cause an index to become selected. If you don't want that, set a flag and check it in the event.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

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

        thanks sir for ur quick reply but sir how can i chk so that after setting the datasource it just go to the next statement in the event not to the selectedindexchanged

        D 1 Reply Last reply
        0
        • M MissionSuccess

          thanks sir for ur quick reply but sir how can i chk so that after setting the datasource it just go to the next statement in the event not to the selectedindexchanged

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Set a class-scope flag (A boolean variable) to true just before you set the datasource of the ComboBox. In the SelectedIndexChanged event, check that flag. It it's set, reset the flag to false and don't do anything in the event handler. If it's false, then you do what you need to accomplish.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          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