Avatar of searchsanjaysharma
searchsanjaysharma
 asked on

Why the cmbcategory.selectedindex change is not working on if condition

Imports System
Imports System.Data
Imports System.Data.SqlClient

Public Class displayitemcodes
    Dim con As SqlConnection
    Dim cmd As SqlCommand
    Dim da As SqlDataAdapter
    Dim dt As DataTable
    Dim s As String

   
    Private Sub cmbcategory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbcategory.SelectedIndexChanged
        If cmbcategory.SelectedItem.ToString() <> "--Select Category--" Then
            MsgBox("Done")
        End If
    End Sub

    Private Sub displayitemcodes_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        con = New SqlConnection("server=ADMIN-PC\SQLEXPRESS;database=stocktracker;Integrated security=true")
        s = "select distinct category from mstitems"
        da = New SqlDataAdapter(s, con)
        dt = New DataTable()
        da.Fill(dt)

        Dim newCustomersRow As DataRow = dt.NewRow()

        newCustomersRow("category") = "--Select Category--"
        dt.Rows.InsertAt(newCustomersRow, 0)

        With cmbcategory


            .DisplayMember = "category"
            .ValueMember = "category"
            .DataSource = dt




        End With
        cmbcategory.Refresh()
    End Sub
End Class
Visual Basic.NET

Avatar of undefined
Last Comment
searchsanjaysharma

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
zofcentr

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
searchsanjaysharma

ASKER
Done, You undestood, Thanx.
searchsanjaysharma

ASKER
ok
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes