I would like to change the background color of RichTextBox which is in a cell of DataGridView.
I have tried use
Me.dgvPartTracking.Item(columnIndex, rowIndex).Style.BackColor = Color.LightGreen
Me.dgvPartTracking.Item(columnIndex, rowIndex).Style.ForeColor = Color.Black
but the result is only the background of cell is changed, and the RichTextBox beackground color is still remaining in white color
The output is as below: Sample Result
The Method I used to assign the RichTextBox into DataGridView.
*I use looping to add the columns and rows as below
Dim Col As New DataGridViewRichTextBoxColumn
Col.Name = "schedule" & columnCount
Col.HeaderText = "" & columnCount
Col.DefaultCellStyle.WrapMode = Windows.Forms.DataGridViewTriState.True
Col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopLeft
Col.Width = 195
Col.ReadOnly = True
Col.SortMode = Windows.Forms.DataGridViewColumnSortMode.NotSortable
Col.Resizable = Windows.Forms.DataGridViewTriState.True
Col.AutoSizeMode = Windows.Forms.DataGridViewAutoSizeColumnMode.NotSet
Col.Visible = True
Me.dgvPartTracking.Columns.Add(Col)
Me.dgvPartTracking.Rows.Add(1)
I didn't set the background color in this code yet, because I would like to change the different background colors for each cells in DataGridView afterward
Item
property of aDataGridView
returns aDataGridViewCell
, not aRichTextBox
. You need to actually access the control in the cell but, if you have done things properly, such a control should only exist while a cell in that column is being edited. We don't know enough about your implementation to know how to access that control but you should, given that you put it there. – jmcilhinney