问题
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