DataGridView calculated field

A

Aleksey Timonin

Hi guys,
I have a DataGridView binded to DataTable.
In the DataTable I have an "ID" field.
How can I create calculated column in the DataGridView that gets as value
object (string) from my list, where item index in the list is equal to value
in "ID" field?

Thanks a lot
Aleksey
 
R

RobinS

So you have an ID field, and in the background you have a list with all the
items, and want to show the value that goes with the ID?

You could use a DataGridViewComboBoxColumn and bind it.

You could also use the Format and Parse events on the cells of the
datagridview. Check the column index, and if it's the right column, in the
Format event you would get the description and show it in the grid; in the
Parse event you would take the description and get the corresponding ID.

There's a great example of this in Brian Noyes's Data Binding Book.

RobinS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top