Solved

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

Posted on 2012-03-14
3
182 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
ID: 37718918
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
ID: 37718935
Done, You undestood, Thanx.
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37718937
ok
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
System32Int Error 8 56
Showdialog 8 29
VS.net 2010 11 18
Variable Event ? 3 20
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 …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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

21 Experts available now in Live!

Get 1:1 Help Now