从DataGridView单元内访问RichTextBox控件属性 [英] Access a RichTextBox Control properties from within DataGridView Cell

查看:292
本文介绍了从DataGridView单元内访问RichTextBox控件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个具有RichTextBox控件的列类型的DataGridView。我这样做的原因是能够执行诸如更改单个单元格中仅部分文本的字体颜色之类的操作。

I'm trying to create a DataGridView that has the column type of RichTextBox control. The reason i'm doing this is to be able to do things like change the font color for only part of the text within a single cell.

从此处使用代码 DataGridView中的RichTextBox单元格

我可以创建一个继承自RichTextBox的DataGridColumn,所以我认为。我现在遇到的问题是如何访问DataGridViewCell的RichTextBox控件属性/方法来执行诸如selectionstart selectionlength等之类的事情。

I can create a DataGridColumn that inherits from RichTextBox or so i think. The problem i'm having now is how do i access the RichTextBox control properties/methods of the DataGridViewCell to do things such as selectionstart selectionlength etc..

代码太有助于说明我的意思。

The next bit of code is too help illustrate what i mean.

DataGridViewRichTextBoxColumn richTextColumn = new DataGridViewRichTextBoxColumn();
this.dataGridView1.Columns.Add(richTextColumn);
this.dataGridView1.Rows.Add("five six seven eight");
//now i want to access the RichTextBox control for the row i just added

Of当然,如果我要彻底解决这个问题,那也很好。

Of course if i'm going about this completely wrong it would be nice know that as well.

推荐答案

如果当前单元格位于编辑模式,则可以使用DataGridView.EditingControl访问当前单元格托管的控件。

If the current cell is in edit mode then you could use DataGridView.EditingControl to access the control hosted by the current cell.

http://msdn.microsoft.com/zh-CN/library/system.windows.forms.datagridview.editingcontrol(v = vs.110).aspx

除非您将RichTextColumn的任何单元格置于编辑模式,否则就不需要RichTextBoxControl,因此DataGridView将不会托管该控件,并且您将无法访问控件。

Unless you bring any cell of the RichTextColumn in edit mode there is no need for the RichTextBoxControl, so the DataGridView won't host the control and you won't be able to access the control.

这篇关于从DataGridView单元内访问RichTextBox控件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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