Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1032701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:07:10+00:00 2026-05-16T14:07:10+00:00

I have .Net 2.0 Windows form containing combobxes. I have written following code to

  • 0

I have .Net 2.0 Windows form containing combobxes. I have written following code to populate combobox and then binding it to ProductType property of type Int.

// Populate Combo

cmbProduct.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
cmbProduct.DataSource = new DataView(productDataSet.Tables[0]);
cmbProduct.DisplayMember = displayColumnName_;
cmbProduct.ValueMember = idColumnaName_;

// Add Databindings

cmbProduct.DataBindings.Add("SelectedValue", this, "ProductType").DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;

ISSUE

  1. Run application.
  2. Click on ComboBox’s drop-down arrow but do not select any item.
  3. Press any keys (such as ALT+TAB, Windows Key etc) which will shift focus from current Windows form application.

This throws Exception and application crashes. Following are the details taken from Output window.

A first chance exception of type ‘System.ArgumentException’ occurred
in System.Windows.Forms.dll Object of type ‘System.DBNull’ cannot be
converted to type ‘System.Int32’. at
System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object
component, Object value)
at System.Windows.Forms.BindToObject.SetValue(Object value)
at System.Windows.Forms.Binding.PullData(Boolean reformat, Boolean force)
at System.Windows.Forms.Binding.Target_PropertyChanged(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.ListControl.OnSelectedValueChanged(EventArgs e)
at System.Windows.Forms.ComboBox.OnSelectedValueChanged(EventArgs e)
at System.Windows.Forms.ComboBox.OnSelectedIndexChanged(EventArgs e)
at System.Windows.Forms.ComboBox.WmReflectCommand(Message& m)
at System.Windows.Forms.ComboBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd,
Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ComboBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg, HandleRef hwnd, Int32 msgMin, Int32 msgMax, Int32 remove)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)

I added some debug statment in event handlers to check the event sequence.
The output window deatails are as shown below :

cmbProduct_SelectionChangeCommitted occured - SelectedValue is NULL
cmbProduct_SelectedValueChanged occured - New SelectedValue is NULL
The thread 0x1728 has exited with code 0 (0x0).
cmbProduct_SelectedIndexChanged occured - New SelectedIndex is -1
The thread 0x1250 has exited with code 0 (0x0).

Question

Why .Net fires SelectionChangeCommitted, SelectedValueChanged and SelectedIndexChanged events when the application loses its focus with combobox state is OPEN ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:07:10+00:00Added an answer on May 16, 2026 at 2:07 pm

    The code looks perfect. The issue maybe because of bug in .net framework. Can some expert confirm this ?

    One workaround to avoid the exception is – store default value of “ProductType” property if SelectedValue is NULL.

    For example, if default value of ProductType is -1 then,

    cmbProduct.DataBindings["SelectedValue"].DataSourceNullValue = -1; 
    

    Hope, this helps!

    Robin

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

JI have written a .NET C# Windows Form app in Visual Studio 2008 that
I have a Windows Form in a VB.NET program with a property of TournID
Hi I have a c# windows form written in .Net 4. In the application
I have a pretty basic windows form app in .Net. All the code is
Im using c# .net windows form application. i have a SQL database with 5
Im using c# .net windows form application. I have many databases created using sql
Im using c# .net windows form application. I have loaded names of all the
Im using c# .net windows application form. I have created many databases with many
Windows form application(.Net 3.5) I have a textbox and a button on the form.
In VB.net 3.5 SP1 I have a Windows Form with three DataGridView controls. One

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.