G
Guest
Hi,
I have bound a collection of type IBindingList to a DataGridView.
Each object in the collection contains various string properties, Customer
Name, Contact Name etc. It also contains a property 'MyOrder' of custom type
'Order'.
The Order class simply contains properties like OrderID, OrderName etc.
I add the columns to the Grid of type DataGridViewTextBoxColumn for the
strings and DataGridViewComboBoxColumn for the 'Order' object, the code for
the combo column is as follows:
DataGridViewComboBoxColumn cboCustmomerOrder = new
DataGridViewComboBoxColumn();
cboCustmomerOrder.HeaderText = "Order";
cboCustmomerOrder.DataPropertyName = "MyOrder";
cboCustmomerOrder.Name = "OrderName";
//cboCustmomerOrder.ValueType = Order;
cboCustmomerOrder.DataSource = m_Cust.OrderCol;
this.dataGridView1.Columns.Add(cboCustmomerOrder);
The datasource is set to a collection of type Order (List<Order>)
Everything displays OK and I can make selections from the dropdowns.
When I try to tab away however, I get the following error:
[System.FormatException] = {"Invalid cast from 'System.String' to
'BusinessComponentExample.Order'."}
I have spent ages trying to find out how to handle this but so far only
found that the error can be trapped as follows:
private void dataGridView1_DataError(object sender,
DataGridViewDataErrorEventArgs e)
{
if (e.Exception != null &&
e.Context == DataGridViewDataErrorContexts.Commit)
{
//Do something
}
}
Obviously I need to cast to type 'Order', but my question is how?
Hope this all makes sense, please let me know if not.
Would be delighted to get an answer or a pointer to a good tutorial.
Couldn't find any that explain how to do this.
Steve
I have bound a collection of type IBindingList to a DataGridView.
Each object in the collection contains various string properties, Customer
Name, Contact Name etc. It also contains a property 'MyOrder' of custom type
'Order'.
The Order class simply contains properties like OrderID, OrderName etc.
I add the columns to the Grid of type DataGridViewTextBoxColumn for the
strings and DataGridViewComboBoxColumn for the 'Order' object, the code for
the combo column is as follows:
DataGridViewComboBoxColumn cboCustmomerOrder = new
DataGridViewComboBoxColumn();
cboCustmomerOrder.HeaderText = "Order";
cboCustmomerOrder.DataPropertyName = "MyOrder";
cboCustmomerOrder.Name = "OrderName";
//cboCustmomerOrder.ValueType = Order;
cboCustmomerOrder.DataSource = m_Cust.OrderCol;
this.dataGridView1.Columns.Add(cboCustmomerOrder);
The datasource is set to a collection of type Order (List<Order>)
Everything displays OK and I can make selections from the dropdowns.
When I try to tab away however, I get the following error:
[System.FormatException] = {"Invalid cast from 'System.String' to
'BusinessComponentExample.Order'."}
I have spent ages trying to find out how to handle this but so far only
found that the error can be trapped as follows:
private void dataGridView1_DataError(object sender,
DataGridViewDataErrorEventArgs e)
{
if (e.Exception != null &&
e.Context == DataGridViewDataErrorContexts.Commit)
{
//Do something
}
}
Obviously I need to cast to type 'Order', but my question is how?
Hope this all makes sense, please let me know if not.
Would be delighted to get an answer or a pointer to a good tutorial.
Couldn't find any that explain how to do this.
Steve