Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ComboBox Explodes

Status
Not open for further replies.

rhnewfie

Programmer
Jun 14, 2001
267
CA
I put a combobox on my form, set the datasource to a datatable, set the value and display members and now when I click on the combo the app crashes.

Any ideas?

Thanks!
 
I don;t think so, the first value in the datatable shows up in the combo
 
What would you like to see other then what is above? That is the only 3 lines that I wrote.
 
rhnewfie,

It sounds like something isn't initialized. How are you filling your data table?

You may want to add watches on the objects involved, (combo box, dataset, data adapter/sql reader), and see what isn't ready to use.


 
What would you like to see other then what is above? That is the only 3 lines that I wrote.

Well that explains it! If this is all of the code you have written:
Code:
cboAccessLevel.DataSource = dt_AccessLevels
cboAccessLevel.ValueMember = "AccessLevelID"
cboAccessLevel.DisplayMember = "AccessLevel"

Then yes, it will fail to execute. You need to declare cboAccessLevel and dt_AccessLevels. Be sure to add columns to the data table, specifically AccessLevelID and AccessLevel. You may also want to populate the data table once you have those columns on it. If you are still having problems after you've written that code, post that code here and maybe we can help.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
LOL!

Well

I have this

Dim dt_AccessLevels As New DataTable("AccessLevel")
cboAccessLevel is also initialized.

dt_AccessLevel then gets its data from an AccessLevels property in a User module.

Then there is this:
Code:
Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        InitializeLocalObjects()
    End Sub

Public Function InitializeLocalObjects()
        
        cboAccessLevel.DataSource = dt_AccessLevels
        cboAccessLevel.ValueMember = "AccessLevelID"
        cboAccessLevel.DisplayMember = "AccessLevel"
 End Function

Could it be that this combobox is on a panel that gets shown and hidden? It starts out hidden.

Now when I first bring up the panel the first access level shows as expected but when I click on the arrow the app crashes. The breakpoint ends up on the frmMain (the mdi parent to the form the combo is on)

Thanks!
 
I think that there is definately something that I am doing wrong. I switched my combobox for a listbox and that blows up too!
 

Have you tried refreshing or setting the data source for your combo box after the data table is filled?

 
blows up" is not a term that has any redeeming value when it comes to debugging.*

Is there and exception that is being thrown?

The three lines you have posted are correct. If the objects are all properly defined and instantiated, then the next most likely culprit is the population of the data table. Ensure that your data is properly loaded, and you may want to check for dbNull values, I'm not sure if Comboboxes and Listboxes will handle them. Also, do you have any code is associated with the combobox that could be firing off when you click the arror?

-Rick

* Unless you are working with systems where the combination of some matter and oxygen at a rapid rate is possible.

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
The error thrown was that listed above.
An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll

Additional information: Object reference not set to an instance of an object.

In a fit of frustration I deleted the panel and all associated controls, redid everything and now there is no error... wierd!

Thanks for all your help everyone!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top