Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linebreak in dataGrid cell...

Status
Not open for further replies.

andypandyswe

Programmer
May 4, 2005
17
SE
I'm trying to show four different values, one above the other, in each dataGrid cell.

I've solved this by combining the four values into a single string with \n inbetween the values. Added the values to a table containing stringcolumns and connected the table to the datagrid. The problem is that in the cell that is active (one always is right from the start) the \n seems to disappear because the values are all on top of eachother and on a single line. When you move the focus to another cell (by klicking it, or using the arrowkeys) that cell's values get garbled and the previous cell is alright. When I set the dataGrid's "Enabled" -value to false the problem goes away but the ability to scroll goes away with it, and since the datagrid is to large to fit in the window, that's not a working solution.

Anyone have a solution or a workaround of some sort?
 
I think you should derive custom column from DataGridTextBoxColumn, let say, DataGridMultiLineBoxColumn
In this class override the Paint() method where you calculate and draw the multiline string (DrawString()).
Override the Edit() method to prevent the user to edit that column.
Next, add the new column to the DataTable.Columns and also to the DataGridTableStyle of the grid.
obislavu
 
Hmmm, Isn't there an easier way to do it? I've already (almost) finished the entire app and in order to implement the above I'd have to do some pretty significant changes to something that finally works... Still, thanx Obislavu. If noone else has any ideas I guess I'll have to try it...
 
obislavu's solution really is the only realistic way to do what you're looking for. Anything else would be a cheap hack which would cause you more troubles in the future.


It's worth the extra effort - back your existing solution up first if it's not in something like SourceSafe already.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top