多行中的一个DataGridView细胞 [英] Multiple lines in a DataGridView cell

查看:96
本文介绍了多行中的一个DataGridView细胞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 C# Windows窗体;

我有一个 DataGridView的与一些细胞。我想在单元格中显示(从1-9)数字。该数字应在彼此在 3×3 格式放置。

I have a DataGridView with a number of cells. I would like to show digits (from 1-9) in the cell. The digits should be placed under each other in a 3x3 format.

我环顾四周,只有结束了一个相当复杂的自定义实施的RichTextBox 细胞。

I looked around, and only ended up with a rather complex custom implementation of a richtextbox cell.

有没有一种方法,我可以得出一个自定义的矩形,然后实现这个为和backgroundImage 电池什么的?小区需要被重新绘制多次。所以我不能随便叫油漆事件我想

Is there a way I can draw a custom rectangle and then implement this as backgroundimage of the cell or something? The cell need to be redrawn several times. So I can't just call the paint event I guess.

注:的细胞不能由用户进行编辑。

Note: The cell must not be edited by the user.

推荐答案

林不知道这是否会满足你,但你可以使用 Environment.NewLine 以创建内部细胞简单的换行

Im don't know if this will satisfy you, but you can use Environment.NewLine to create simple line break inside cell.

例如:

string nl = Environment.NewLine; // new line variable
string data = "1 2 3" + nl + "4 5 6" + nl + "7 8 9";



以后添加:

Added later:

作为<一个HREF =htt​​p://stackoverflow.com/users/920798/adrian>阿德里安注释中说的 - 你将需要:

As Adrian said in comments - you will need to:


  1. 的DataGridViewColumn 设置为WrapMode DataGridViewTriState.True

  1. set the WrapMode for the DataGridViewColumn to DataGridViewTriState.True

请确保您设置一个高度的行,或者设置在DataGridView的 AutoSizeRowsMo​​de DataGridViewAutoSizeRowsMo​​de.AllCells

make sure you set a height for the row, or set the DataGridView's AutoSizeRowsMode to DataGridViewAutoSizeRowsMode.AllCells

如果您不希望编辑列 - 你可以设置 DataGridView.Column.ReadOnly 属性真正

If you don't want to edit that column - you can set DataGridView.Column.ReadOnly property to true.

这篇关于多行中的一个DataGridView细胞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆