Solved

"Object reference not set to an instance of an object." How to correct this during combobox binding.

Posted on 2012-03-21
3
197 Views
Last Modified: 2012-03-21
The error comes at bold line. I am binding state combo with district combo, i.e when any state is selected then only district should get selected.


 Private Sub cmbstate_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbstate.SelectedIndexChanged
        cmbstate.SelectedIndex = -1
       If CType(cmbstate.SelectedItem, DataRowView)("state").ToString() <> "--Select State--" Then
            binddistricts()
        End If
    End Sub
    Public Function binddistricts()
        s = "select distinct district from statedistrict where flag=1 and state='" & cmbstate.SelectedItem & "' order by district"
        da = New SqlDataAdapter(s, con)
        dt = New DataTable()
        da.Fill(dt)

        Dim newCustomersRow As DataRow = dt.NewRow()

        newCustomersRow("district") = "--Select District--"
        dt.Rows.InsertAt(newCustomersRow, 0)

        With cmbdistrict
            .DisplayMember = "district"
            .ValueMember = "district"
            .DataSource = dt
        End With
        cmbdistrict.Refresh()
    End Function
0
Comment
Question by:searchsanjaysharma
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
appari earned 500 total points
ID: 37750989
why are you setting selectedindex to -1 before the check?

remove this line and check
cmbstate.SelectedIndex = -1
0
 

Author Comment

by:searchsanjaysharma
ID: 37751044
But i want to reset cmbdistrict, if cmbstates has been changed.
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37751045
ok
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 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