CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2005
    Posts
    2

    Get BackColor value of the current cell in datagrid

    Hi there,

    How could I get the value of the BackColor property of the current cell in the datagrid? I'm thinking of using mouse click event to play with BackColor property of the cell.

    The idea is shown:
    Code:
    Mouse_Down_Event( )
    {
         if( MyGrid.CurrentCell.BackColor == Color.Red)
             MyGrid.CurrentCell.BackColor = Color.White
         else
             MyGrid.CurrentCell.BackColor = Red
    }
    I tried to override Paint() method, and work with the properties of the cell through Paint() method but it didn't work.
    I tried to play around the textBox object's properties, but it didn't work.

    Could anyone help me please?

    *I don't mind to use either DataGrid object or FlexGrid object.

    Have an enjoyable cup of coffee .
    illy Maker

  2. #2
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Re: Get BackColor value of the current cell in datagrid

    You will need to use a custom ColumnStyle. Here is an example that change the ForeColor of a cell based on a condition.
    How to set the ForeColor of the text in a cell based on a condition.
    You can do the same in order to change the BackColor.

  3. #3
    Join Date
    Dec 2005
    Posts
    2

    Re: Get BackColor value of the current cell in datagrid

    Thanks for your post. I've seen this idea before, but my lost solution(my problem) is little deffirent.
    Simply, what I whant to do is:
    Code:
    Event Button1.Click() // instead of MouseDown event
    {
         if(SelectedCellRange.BackColor == Color.White)
              SelectedCellRange.BackColor = Color.Red;
         else
              SelectedCellRange.BackColor = Color.White;
    }
    or like this:
    Code:
    Event MyGrid.CellEnter()
    {
         if( CurrentCell.BackColor == Color.White)
              CurrentCell.BackColor = Color.Red;
         else
              CurrentCell.BackColor = Color.White;
    }
    Thanks again.

    Coffee Maker

  4. #4
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Re: Get BackColor value of the current cell in datagrid

    I don't know if this is exactly what you need, but DataGrid has a property called SelectedBackColor. It will paint the whole Row when it is selected in a different color.
    You cannot paint a single cell easily. Only way I can think of is by deriving from DataGridTextBoxColumn, and handle the events of the TextBox property (When you inherit from this class you have access to the actual TextBox which is shown when the user edits the cell). You can set the back color of the TextBox to Red, and override the Paint method of the Column Style to paint other back color.

  5. #5
    Join Date
    Jul 2002
    Location
    India
    Posts
    505

    Re: Get BackColor value of the current cell in datagrid


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured