?
Solved

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

Posted on 2012-03-14
3
Medium Priority
?
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

743 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