简体   繁体   中英

Refreshing value in a bound ComboBoxCell

I'm developing a WinForm app in C# (VS 2008).

I have a DataGridView bound to a DataTable (Fields) and one additional column - ComboBoxColumn . It is called RefFieldName and it is binded the same fieldsdatatable. It fills the column (RefFieldId) in this DataGridView with ID of a field chosen in the ComboBox .

Everything works except of displaying the name of field when my RefFieldId cell is already set. I need to display a name of the field with ID from RefFieldId in my ComboBox cell.

How do I refresh my ComboBox in this way?

Okey!

I've found the solution, but it is not as elegant as I expected.

I've written a method that for each record checks all records in the table and looks for fit. Then it updates the Name:

row.Cells["RefFieldName"].Value = refRow.Cells["FieldName"].Value;

Then It is necessary to handle event DataError and create an empty method for that. If somebody knows better solution it would be great!

Regards, Kuba.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM