Solved

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

Posted on 2012-03-14
3
179 Views
Last Modified: 2012-03-14
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
0
Comment
Question by:searchsanjaysharma
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
zofcentr earned 500 total points
Comment Utility
I am not sure whether I understand clearly your problem.
If you are asking why delegate cmbcategory_SelectedIndexChanged has not been called then answer is that maybe you did not have bound this method correctly the event.
Check properties/events of combobox.

If event is raised and method is called but statement (
If cmbcategory.SelectedItem.ToString() <> "--Select Category--") always returns false
then answer is : cmbcategory.SelectedItem.ToString() returns string equal to "System.Data.DataRowView".

Try something like this:
If CType(cmbcategory.SelectedItem, DataRowView)("category").ToString() <> "--Select Category--"
0
 

Author Comment

by:searchsanjaysharma
Comment Utility
Done, You undestood, Thanx.
0
 

Author Closing Comment

by:searchsanjaysharma
Comment Utility
ok
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now