ArgumentException was unhandled Error
I am a former Basic programmer and am fairly new to the modern VB.net. I believe I have a fair understanding of the basics of OO programming but consider myself a beginner at Visual Basic .Net. I am using VS2010 Pro to develop an application for an American Legion Post to track members address, date joined and date deceased. I am using the "detail" layout of a dataset on the member add/edit form. I have a listbox bound to a datasource which lists the last name of all members. I also use a textbox to further limit the list of names; i.e., as a name is typed in, the list reduces with each letter entered. My first issue arose with the Deceased date-time-picker (dtp) field; I need the Deceased dtp to be blank if the member is living. I was able accomplish this by declaring row, setting it to equal DataRowView.Current and setting the Deceased dtp to a custom format of "". All seemed good until I selected a name from the listbox, I then received a DBnull error and realized that the DataRowView.Current = nothing. My solution was to set the dtp to custom format if the listbox.SelectedItem < 0. This seemed to work except now I receive the error "ArgumentException was unhandled. Cannot bind to the property or column Deceased on the DataSource. Parameter name: dataMember." This error only occurs when a deceased member is highlighted in the listbox and the "Return to Main" button is clicked; I am totally baffled on what is causing this error and how to resolve it. Any assistance would be greatly appreciated.
Last edited by EdB; 08-08-2013 at 10:02 PM.
You shouldn't bind a DateTimePicker if the underlying data can be null. The usual way to work with nullable data in a DateTimePicker is to set the ShowCheckBox property to True and then move data back and forth manually, setting the Checked property to True if there is a value to display and False otherwise.
Setting the ShowCheckBox worked - thank you!