C1 Flex Grid - Focus Style and HIghlight Style

i have a component one flex grid with three columns.

I want to set the whole row to be blue with white text when the user selects that row and gray with black text when the grid loses focus.
Who is Participating?
mdouganConnect With a Mentor Commented:
That's because you're setting the Focus style, in your example, you could set the Highlight style instead:

      tblView.Styles.Highlight.BackColor = SystemColors.Highlight

You can also set an entire row or column to a new style that you create using the following syntax

    Dim FixedStyle As C1.Win.C1FlexGrid.CellStyle

     ' clear out any previously set style attributes
      tblView.Redraw = False

      FixedStyle = tblView.Styles.Add("FauxFixed")
      FixedStyle.BackColor = Color.WhiteSmoke

      tblView.Cols(0).Style = tblView.Styles("FauxFixed")
      tblView.Rows(0).Style = tblView.Styles("FauxFixed")

      tblView.Redraw = True
You can do it at design time, buy highlighting the grid, expanding the Styles property, then looking for the Highlighted style and setting the background and forecolor properties.  Then, you can set the same properties for the Normal style for when the row is not highlighted.  You can also set these styles at run time, let me know if you need the code for that.

The key is figuring out which style to set... you said, "when the grid loses focus", did you mean when the row is no longer highlighted?  Or when the whole grid loses focus?  I don't believe that the grid has a built-in style for this, so, you'd probably have to alter the Normal style when the control gets a Lost Focus and a Got Focus event.

Also, I don't believe the grid has a built-in style for "selected" rows.  Typically, rows selected by the user clicking them become highlighted, and so it is the Highlighted style you want to set... however, I seem to remember cases where things might be selected in code, but do not appear highlighted on the screen.

Once you know which styles you want to set, let me know and I can show you code for setting them at runtime if you need to... and/or, if you want to create a new style and apply that to any part of the grid, I can show you how to do that too.
tricks801Author Commented:
Im familiar with the Styles properties. The problem with these are that  they are of type CellStyleCollection, so they only affect one cell at a time.

Ex. .Styles.Focus.BackColor = SystemColors.Highlight will only set the color of the selected cell.

I decided to use the TrueDB grid. thanks
All Courses

From novice to tech pro — start learning today.