3

I'd like to create a nicer-looking DataGridView to display data from my SQL database in. Specifically, I'm looking to replicate something like this:

enter image description here

Is there some sort of add-on for Visual Studio that could help me get the DataGridView looking like this? Or have I missed some formatting/display options?

Grant Winney
  • 65,241
  • 13
  • 115
  • 165
jdewitte
  • 131
  • 3
  • 13

4 Answers4

2

I've done this kind of thing many times, and the other answers are correct in that you have to manually do it by setting the cell styles. There are 3rd party options, but after messing with them for a while I always end up scrapping it because of limitations you occasionally run into with proprietary controls (plus they usually cost money). If you are able to use WPF instead of WinForms, though, I highly recommend using it. It is much easier to do all kinds of styling using WPF's MVVC pattern.

jugg1es
  • 1,560
  • 18
  • 33
1

Use the "Style" property -

DataGridView1.Item(ColumnIndex, RowIndex).Style.BackColor = Color
DataGridView1.Item(ColumnIndex, RowIndex).Style.ForeColor = Color
DamianB
  • 361
  • 2
  • 5
  • 16
1

Cell styling could be your friend. You can find some reference in MSDN Ref1, Ref2. Meantime, more advanced out of the box styling can be easily achievable through third party controls libraries like Infragistic or DevExpress .

S.N
  • 4,910
  • 5
  • 31
  • 51
1

You can try this .. for example ..

dgv.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
dgv.ColumnHeadersDefaultCellStyle.BackColor = Color.Aquamarine
dgv.ColumnHeadersDefaultCellStyle.ForeColor = Color.Red
dgv.ColumnHeadersHeight = 30
dgv.GetType.InvokeMember("DoubleBuffered", Reflection.BindingFlags.NonPublic Or _
                Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.SetProperty, Nothing, dgv, New Object() {True})

dgv.Columns(1).DefaultCellStyle.BackColor = Color.Yellow

Add this in Form.load event

dgv.EnableHeadersVisualStyles = False
matzone
  • 5,703
  • 3
  • 17
  • 20