Access a RichTextBox Control properties from within DataGridView Cell

微笑、不失礼 提交于 2019-12-25 02:44:19

问题


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.

Using the code from here RichTextBox Cell in a DataGridView

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 course if i'm going about this completely wrong it would be nice know that as well.


回答1:


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/en-us/library/system.windows.forms.datagridview.editingcontrol(v=vs.110).aspx

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.



来源:https://stackoverflow.com/questions/20970870/access-a-richtextbox-control-properties-from-within-datagridview-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!