Casting error question
-
I am using:
foreach (DebtorDataSet.PaymentArrangementsRow row in debtorDataSet.PaymentArrangements.Rows) { if (row.PaymentArrangementID != -1 && row.PaymentTypeID == Convert.ToInt32(paymentCategoryComboBox.SelectedItem) && row.ArrangementComplete == false) { row.ArrangementComplete = true; row.ArrangementDate = DateTime.Today; } }
but this is giving me the error: 'Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible'' I am not sure how to correct this. Any help would be much appreciated please. -
I am using:
foreach (DebtorDataSet.PaymentArrangementsRow row in debtorDataSet.PaymentArrangements.Rows) { if (row.PaymentArrangementID != -1 && row.PaymentTypeID == Convert.ToInt32(paymentCategoryComboBox.SelectedItem) && row.ArrangementComplete == false) { row.ArrangementComplete = true; row.ArrangementDate = DateTime.Today; } }
but this is giving me the error: 'Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible'' I am not sure how to correct this. Any help would be much appreciated please.I'm not really sure about it, but because there is only one line where you convert something I would replace
Convert.ToInt32(paymentCategoryComboBox.SelectedItem)
with
Convert.ToInt32(paymentCategoryComboBox.SelectedItem.ToString())
But in general SelectedItem is not from the type 'System.Data.DataRowView' so I'm a little bit confused with it. But maybe that helps.
Greetings Covean
-
I'm not really sure about it, but because there is only one line where you convert something I would replace
Convert.ToInt32(paymentCategoryComboBox.SelectedItem)
with
Convert.ToInt32(paymentCategoryComboBox.SelectedItem.ToString())
But in general SelectedItem is not from the type 'System.Data.DataRowView' so I'm a little bit confused with it. But maybe that helps.
Greetings Covean
Many thanks for your reply. Sill me realised that I needed SelectedValue instead of selectedItem to do the job. The perils of late night coding .......
-
Many thanks for your reply. Sill me realised that I needed SelectedValue instead of selectedItem to do the job. The perils of late night coding .......
-
Many thanks for your reply. Sill me realised that I needed SelectedValue instead of selectedItem to do the job. The perils of late night coding .......
What type is the SelectedValue? If it's an int, why convert an int to an int? Just cast it. If not, then you can probably cast it anyway. I find the Convert class to be nearly entirely useless; try not to use it.