Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridViewCellStyle
 

DataGridViewCellStyle

Hi All,

How do i canchange font style for specific cell in datagridview?

I have this code:

================================================

private void btStart_Click(object sender, EventArgs e)

{

int maxChanges = 3;

double maxSize = 12;

if (this.dgvText.SelectedRows.Count > 0)

{

DataGridViewCellStyle style = new DataGridViewCellStyle();

for (int i = 0; i < maxChanges; i++)

{

System.Threading.Thread.Sleep(100);

maxSize = maxSize - 0.5;

style.Font = new Font("Arial", (float)maxSize, FontStyle.Regular);

this.dgvText.SelectedRows[0].Cells[this.clmnText.Index].Style = style;

this.dgvText.SelectedRows[0].DefaultCellStyle = style;

}

for (int y = 0; y <= maxChanges; y++)

{

System.Threading.Thread.Sleep(100);

maxSize = maxSize + 0.5;

style.Font = new Font("Arial", (float)maxSize, FontStyle.Regular);

this.dgvText.SelectedRows[0].Cells[this.clmnText.Index].Style = style;

}

}

}

================================================

But this code only works well when i update the DataGridView using the following instruction after the style change instruction:

this.dgvText.SelectedRows[0].Cells[this.clmnText.Index].Style = style;

this.dgvText.Update();

Do you know any other away to update/refresh the cell style, but only forthe specific cell?

Many Thanks

Sandro Peixoto

Sandro Peixoto  Saturday, June 07, 2008 2:06 PM
You can get the datagridview to redraw a cell with its InvalidateCell method

http://msdn.microsoft.com/en-us/library/150892dc(vs.85).aspx
Ken Tucker  Sunday, June 08, 2008 3:15 PM
You can get the datagridview to redraw a cell with its InvalidateCell method

http://msdn.microsoft.com/en-us/library/150892dc(vs.85).aspx
Ken Tucker  Sunday, June 08, 2008 3:15 PM

Hi,

The InvalidateCellmethod doesn't apply well the new styles to the cell using my codeSadI don't know why...

======================================================

DataGridViewCellStyle style = new DataGridViewCellStyle();
for (int i = 0; i < maxChanges; i++)
{
System.Threading.Thread.Sleep(100);
maxSize = maxSize - 0.5;
style.Font = new Font("Arial", (float)maxSize, FontStyle.Regular);
this.dgvText.SelectedRows[0].Cells[this.clmnText.Index].Style = style;
this.dgvText.InvalidateCell(this.clmnText.Index, this.dgvText.SelectedRows[0].Index);
}

======================================================

Many Thanks

Sandro Peixoto

Sandro Peixoto  Sunday, June 08, 2008 3:41 PM

You can use google to search for other answers

Custom Search

More Threads

• Data Source using Dynamic Connection String
• New to VB.NET - How can I add line numbers to DataGridView rows using VB.NET?
• Databinding: Updating database through Save button on binding navigator toolbar
• Drag-and-drop using a DataView as DataSource
• datagrid
• Export to Excel from Datagrid?
• How do I disable a ListViewItem (VB.NET 2003)
• datagridview how end ediiting
• Problem in Implement Virtual Mode in the Windows Forms DataGridView Control Example
• Simple databinding problem