0

I have a DataGrid which displays in one of its columns an "Employee ID". I would like to programmatically either while binding or after binding, change those cells' values from the employee id to the full name of the employee which is easily available.

Bottom line, how to change a cell's value after or during binding based on the cell's value.

SO:

1 would become jane doe 2 would become whatever james

User would not see the ids, just the post processed full name. How can this be done?

Currently I bind data to the datagrid from a datatable from sql. I tried tapping into the data through the datatable before binding it instead but came to the issue that the employee id is an int32 and i'd have to change it to string and could not find a decent way of doing that either.

Any ideas would be greatly appreciated!

  • Do you transfer data from the sql server to a data table locally, whereafter you bind the table to the dataGridView or do you bind the data grid directily to the sql? – MasterXD Aug 02 '16 at 22:00
  • 1
    Is there a reason why your SQL selects the Employee ID in the first place? If not, you should be able to omit Employee ID from your SQL, include the Employee Name in your SQL. This change should flow through to your datatable. If it does not, then please show us where you run in to trouble with the datatable. This should be handled in SQL / datatable, and not as a replacement later. – devlin carnate Aug 02 '16 at 22:01
  • I found my solution to be cloning the DataTable and changing the Column type from Int to String, then binding that second DataTable after manipulating the values needed. Reason for employee id is because it is the signature of who created the data in that row, unfortunately (and it should have been perhaps) but the table itself wasnt formatted with the full name just the employee id, for tracking purposes etc. – Javier Avalos Aug 02 '16 at 22:11
  • P.S. Thank you for your quick responses :) I had not tested out the community with a question yet, since most answers had been previously asked, and in a convoluted way mine was too using the idea below: http://stackoverflow.com/questions/9028029/how-to-change-datatype-of-a-datacolumn-in-a-datatable – Javier Avalos Aug 02 '16 at 22:16

0 Answers0