?
Solved

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

Posted on 2012-03-14
3
Medium Priority
?
192 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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Loops Section Overview
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

850 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