Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > formatting multiple fields in a single column
 

formatting multiple fields in a single column

I have a datagridview bound to a datasource that is used as the master in a master detail arrangement.
It has lastname and firstname fields, I need a single field with the names concatanated.
I don't see how to plug in a formatting function and assign it to a column
In the java application that I am porting, similar issues were handled by reading the dataset into a class and calling a formating function when the field is displayed. I don't see how to do this in the datagridview/datadapter world of C#
Thanks
wg_self  Friday, April 25, 2008 8:05 PM
If you are looking to format bound data displayed in a databound textbox you need to use the Format event of the data binding.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.binding.format.aspx
Ken Tucker  Monday, April 28, 2008 4:49 PM
I would bind my textbox to a bindingsource and in the format event you can use the bindingSource's Current property to gain access to the other columns in that row.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.bindingsource.current.aspx
Ken Tucker  Tuesday, April 29, 2008 5:43 PM
jal2  Saturday, April 26, 2008 6:05 AM
Thanks, but that does not really address the issue. I have a form with a few dozen textboxes bound to database fields via a dataAdapter. Most of the boxes are bound to a single field but some of them need to be formated with data from separate fields. ie. 268 in AREA_CODE and 245-5890 in PHONE would be displayed as (268) 245-5890 on the form. I see no way to do this in designer.
wg_self  Monday, April 28, 2008 2:04 PM
If you are looking to format bound data displayed in a databound textbox you need to use the Format event of the data binding.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.binding.format.aspx
Ken Tucker  Monday, April 28, 2008 4:49 PM
That gets me almost there. I have one textbox that displays data from five fields. I can handle the concatenation etc in the format event handler but how do I get the data. I only see how to bind one field to the control.
Thanks,
Glen
wg_self  Monday, April 28, 2008 6:59 PM
I would bind my textbox to a bindingsource and in the format event you can use the bindingSource's Current property to gain access to the other columns in that row.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.bindingsource.current.aspx
Ken Tucker  Tuesday, April 29, 2008 5:43 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView Update
• combo box
• How to display an XML file in a DataGridView
• Problem with datagrid ... pls help
• DatagridviewButton with an image
• Multiple select is not working for datagridview
• objectdatasource not found a nongeneric
• Refresh a "view" in datagridview
• Data Adapter of the TableAdapter is Internal
• DataView problem after DataAdapter.Fill