DataGrid Cell: Custom Font/Backcolor/Format cell by cell (VB.NET)

Discussion in 'Microsoft Dot NET Framework Forms' started by DraguVaso, Dec 16, 2003.

  1. DraguVaso

    DraguVaso Guest

    Hi,

    I'm looking for a nice way to format the cell of my datagrid according to
    some predefined 'rules'. I found a lot on the site of George shepherd, but
    it wasn't really what I was looking for:

    I found there: How can I change the font used in a Gridcell on a cell by
    cell or row by row basis. Wih this code I am able to change the
    Font/Background/... based on the position of the field (column and row). The
    problem is: it only changes the font etc, and not the format of it.
    http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q927q

    Another usefull thing: How can I perform custom formatting on the cells in
    my datagrid: This changes the format of a cell: like "1234" becomes "12-34"
    and stuff like that.
    http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q881q

    BUT (and now it comes): I'm not able to make something liek a 'merge' of
    these two things. What I actually need is being able to change Font,
    Backgroundcolor, Format, etc based on the entire row!!

    For example: If the value in one field is zero, another Field has to get
    marked in a specific Color (in the same record offcourse).

    Anybody got any idea? Or better: A nice working example, or somewhere a
    Class that takes care for all this stuff.

    Thanks a lot in advance!

    Pieter
     
    DraguVaso, Dec 16, 2003
    #1
    1. Advertisements

  2. DraguVaso

    Nick Harris Guest

    To do this, you'd have to do quite of bit of extending of the datagrid and
    override some of the draw events to achieve the desired results. When I
    looked at the amount of time it would take I ended up buying Infragistics
    ..NET Advantage 3.0. I downloaded & installed it (5min), and used their
    UltraGrid, which has quite a few of these features available during design
    time.

    I got everything I wanted in about an hour, which included much more complex
    logic than you seem to need. As a brief example, I had a cell that I wanted
    to color blue of cell 3 and cell 7 if they both equalled "yes". I simply
    utilized the Initialize_Row event, which passes in RowEventArgs for each row
    as it it retrieved from your datasource and/or class.

    From there I could just
    /**/
    if (e.Row.Cells["ColName3"].Value == "Yes" &&
    e.Row.Cells["ColName7"].Value == "Yes")
    {
    e.Row.Cells["MyCellToHightlightColName"].CellAppearance.BackColor =
    System.Drawing.Color.Blue;
    }
    /**/

    or something to that effect.

    Hope this helps!

    Nick Harris, MCP, CNA, MCSD
    Director of Software Services
    http://www.VizSoft.net



    "DraguVaso" <> wrote in message
    news:3fdf2716$0$16026$...
    > Hi,
    >
    > I'm looking for a nice way to format the cell of my datagrid according to
    > some predefined 'rules'. I found a lot on the site of George shepherd, but
    > it wasn't really what I was looking for:
    >
    > I found there: How can I change the font used in a Gridcell on a cell by
    > cell or row by row basis. Wih this code I am able to change the
    > Font/Background/... based on the position of the field (column and row).

    The
    > problem is: it only changes the font etc, and not the format of it.
    > http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q927q
    >
    > Another usefull thing: How can I perform custom formatting on the cells in
    > my datagrid: This changes the format of a cell: like "1234" becomes

    "12-34"
    > and stuff like that.
    > http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q881q
    >
    > BUT (and now it comes): I'm not able to make something liek a 'merge' of
    > these two things. What I actually need is being able to change Font,
    > Backgroundcolor, Format, etc based on the entire row!!
    >
    > For example: If the value in one field is zero, another Field has to get
    > marked in a specific Color (in the same record offcourse).
    >
    > Anybody got any idea? Or better: A nice working example, or somewhere a
    > Class that takes care for all this stuff.
    >
    > Thanks a lot in advance!
    >
    > Pieter
    >
    >
    >
    >
    >
    >
    >
    >
     
    Nick Harris, Dec 17, 2003
    #2
    1. Advertisements

  3. Hi DraguVaso,

    if you override the column's Paint method, you should be able to access other fields of the _DataSource_. The necessary information
    is passed in the parameters - CurrencyManager and rowNum:

    protected override void Paint( Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight )

    In the paint method you have the complete control over the cell painting.
    hth, urlich.


    "DraguVaso" <> schrieb im Newsbeitrag news:3fdf2716$0$16026$...
    > Hi,
    >
    > I'm looking for a nice way to format the cell of my datagrid according to
    > some predefined 'rules'. I found a lot on the site of George shepherd, but
    > it wasn't really what I was looking for:
    >
    > I found there: How can I change the font used in a Gridcell on a cell by
    > cell or row by row basis. Wih this code I am able to change the
    > Font/Background/... based on the position of the field (column and row). The
    > problem is: it only changes the font etc, and not the format of it.
    > http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q927q
    >
    > Another usefull thing: How can I perform custom formatting on the cells in
    > my datagrid: This changes the format of a cell: like "1234" becomes "12-34"
    > and stuff like that.
    > http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q881q
    >
    > BUT (and now it comes): I'm not able to make something liek a 'merge' of
    > these two things. What I actually need is being able to change Font,
    > Backgroundcolor, Format, etc based on the entire row!!
    >
    > For example: If the value in one field is zero, another Field has to get
    > marked in a specific Color (in the same record offcourse).
    >
    > Anybody got any idea? Or better: A nice working example, or somewhere a
    > Class that takes care for all this stuff.
    >
    > Thanks a lot in advance!
    >
    > Pieter
    >
    >
    >
    >
    >
    >
    >
    >
     
    Ulrich Sprick, Dec 23, 2003
    #3
  4. DraguVaso

    DraguVaso Guest

    Thanks!

    I was indeed able to to this by overriding the paint-method for the colors
    etc.
    For the formatting of the cells I had to override the
    GetcolumnValueAtRow-event.

    I found most of these things on the site:
    http://www.syncfusion.com/FAQ/WinForms

    Thanks anyway!

    Pieter
     
    DraguVaso, Dec 23, 2003
    #4
  5. DraguVaso

    Jan Tielens Guest

    If compiled some of the features on the Windows Forms FAQ, plus a lot more,
    in my ExtendedDataGrid:
    http://dotnet.leadit.be/extendeddatagrid/

    It's a free control, so if your intrested: feel free to try it!

    --
    Greetz,
    Jan
    __________________________________
    Read my weblog: http://weblogs.asp.net/jan
    "DraguVaso" <> schreef in bericht
    news:3fe80519$0$5252$...
    > Thanks!
    >
    > I was indeed able to to this by overriding the paint-method for the colors
    > etc.
    > For the formatting of the cells I had to override the
    > GetcolumnValueAtRow-event.
    >
    > I found most of these things on the site:
    > http://www.syncfusion.com/FAQ/WinForms
    >
    > Thanks anyway!
    >
    > Pieter
    >
    >
    >
     
    Jan Tielens, Jan 6, 2004
    #5
  6. Really GREAT!!!

    Jan, I've been working on datagrid columnstyles a little bit, too:

    http://www.i-syn.gmxhome.de/devcom/colstyles/intro.htm

    Perhaps we can join our forces? I'd be delighted!
    Cheers,
    ulrich



    "Jan Tielens" <> schrieb im Newsbeitrag news:#...
    > If compiled some of the features on the Windows Forms FAQ, plus a lot more,
    > in my ExtendedDataGrid:
    > http://dotnet.leadit.be/extendeddatagrid/
    >
    > It's a free control, so if your intrested: feel free to try it!
    >
    > --
    > Greetz,
    > Jan
    > __________________________________
    > Read my weblog: http://weblogs.asp.net/jan
    > "DraguVaso" <> schreef in bericht
    > news:3fe80519$0$5252$...
    > > Thanks!
    > >
    > > I was indeed able to to this by overriding the paint-method for the colors
    > > etc.
    > > For the formatting of the cells I had to override the
    > > GetcolumnValueAtRow-event.
    > >
    > > I found most of these things on the site:
    > > http://www.syncfusion.com/FAQ/WinForms
    > >
    > > Thanks anyway!
    > >
    > > Pieter
    > >
    > >
    > >

    >
    >
     
    Ulrich Sprick, Jan 7, 2004
    #6
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. [ F e r n a n d o  L o p e s ]

    How to format datagrid cell for money format?

    [ F e r n a n d o L o p e s ], Aug 27, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    4
    Views:
    1,597
    Eric Cadwell
    Sep 16, 2003
  2. Geraldine Hobley

    change the backcolor of a column in a datagrid

    Geraldine Hobley, Oct 24, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    2
    Views:
    210
    geraldine hobley
    Oct 27, 2003
  3. Custom Date Format for VB.NET Datagrid Column

    , Apr 26, 2005, in forum: Microsoft Dot NET Framework Forms
    Replies:
    4
    Views:
    1,728
  4. Guest

    Control.BackColor (AmbientProperties.BackColor)

    Guest, Nov 29, 2005, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    472
    Guest
    Nov 29, 2005
  5. ray well

    Control.BackColor Transparency, Control.BackColor = Color.Transparent

    ray well, Jun 12, 2006, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    1,066
    Stoitcho Goutsev \(100\)
    Jun 12, 2006
Loading...

Share This Page