From: DIOS on
VB2005 - I have a DataGridView with cells of various background colors
set with various methods. In the end I want to determine a color for
an individual cell, ie what the user sees. According to MSDN there is
a hierarchy of how the cell gets colored. Is there one function that
will get me the "final" color or do i have to step through the entire
DataGridViewCellStyle Class?

AGP
From: Onur Güzel on
On Jun 4, 9:58 pm, DIOS <sindi...(a)gmail.com> wrote:
> VB2005 - I have a DataGridView with cells of various background colors
> set with various methods. In the end I want to determine a color for
> an individual cell, ie what the user sees. According to MSDN there is
> a hierarchy of how the cell gets colored. Is there one function that
> will get me the "final" color or do i have to step through the entire
> DataGridViewCellStyle Class?
>
> AGP

Doesn't this work:

' Set desired color from Color structure
DataGridView1.Item(Column, Row).Style.BackColor = Color

or

DataGridView1.CurrentCell.Style.BackColor = Color

HTH,

Onur Güzel
From: DIOS on
On Jun 4, 2:09 pm, Onur Güzel <kimiraikkone...(a)gmail.com> wrote:
> On Jun 4, 9:58 pm, DIOS <sindi...(a)gmail.com> wrote:
>
> > VB2005 - I have a DataGridView with cells of various background colors
> > set with various methods. In the end I want to determine a color for
> > an individual cell, ie what the user sees. According to MSDN there is
> > a hierarchy of how the cell gets colored. Is there one function that
> > will get me the "final" color or do i have to step through the entire
> > DataGridViewCellStyle Class?
>
> > AGP
>
> Doesn't this work:
>
> ' Set desired color from Color structure
> DataGridView1.Item(Column, Row).Style.BackColor = Color
>
> or
>
> DataGridView1.CurrentCell.Style.BackColor = Color
>
> HTH,
>
> Onur Güzel

Sure it does. that's not my problem though. Let me restate,
In my processing I color the cells of the DGV using various
methods...rowstyle, cell style, etc.
I present that to the user. Now they click on a cell and i need to
determine the color that they see, the final color of the cell.
Because of the hierarchy of the DataGridViewCellStyle Class simply
using "If CurrentCell.Style.BackColor = Color.Red" will not work.
The cell will be colored red but its another style that set it.
According to MSDN they have a hierarchy of what is used to color the
cell.
My question is rather than cycling through all the class properties to
get to the final color that the user sees is there a super function
that
gives me the final rendered cell color? I'm interested in how to read
the final color of the cell.

AGP
From: Onur Güzel on
On Jun 4, 10:28 pm, DIOS <sindi...(a)gmail.com> wrote:
> On Jun 4, 2:09 pm, Onur Güzel <kimiraikkone...(a)gmail.com> wrote:
>
>
>
> > On Jun 4, 9:58 pm, DIOS <sindi...(a)gmail.com> wrote:
>
> > > VB2005 - I have a DataGridView with cells of various background colors
> > > set with various methods. In the end I want to determine a color for
> > > an individual cell, ie what the user sees. According to MSDN there is
> > > a hierarchy of how the cell gets colored. Is there one function that
> > > will get me the "final" color or do i have to step through the entire
> > > DataGridViewCellStyle Class?
>
> > > AGP
>
> > Doesn't this work:
>
> > ' Set desired color from Color structure
> > DataGridView1.Item(Column, Row).Style.BackColor = Color
>
> > or
>
> > DataGridView1.CurrentCell.Style.BackColor = Color
>
> > HTH,
>
> > Onur Güzel
>
> Sure it does. that's not my problem though. Let me restate,
> In my processing I color the cells of the DGV using various
> methods...rowstyle, cell style, etc.
> I present that to the user. Now they click on a cell and i need to
> determine the color that they see, the final color of the cell.
> Because of the hierarchy of the DataGridViewCellStyle Class simply
> using "If CurrentCell.Style.BackColor = Color.Red" will not work.
> The cell will be colored red but its another style that set it.
> According to MSDN they have a hierarchy of what is used to color the
> cell.
> My question is rather than cycling through all the class properties to
> get to the final color that the user sees is there a super function
> that
> gives me the final rendered cell color? I'm interested in how to read
> the final color of the cell.
>
> AGP

I may not have understood your question well because of the word
"final" (what you meant), but my consideration is that you can store
the color in a variable after user selected the color like that:

' Declare myColor as a global variable at class-level
Dim myColor As Color


Handle CellStyleContentChanged Event and inside:

Private Sub DataGridView1_CellStyleChanged _
(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DataGridViewCellStyleContentChangedEventArgs)
Handles DataGridView1.CellStyleContentChanged

myColor = e.CellStyle.BackColor

End Sub

Retrieve "final" color when you want by means of myColor.
"myColor" gets updated on every raise of CellStyleContentChanged
event. (eg: Msgbox(myColor.toString))

HTH,

Onur Güzel
From: DIOS on
On Jun 4, 3:19 pm, Onur Güzel <kimiraikkone...(a)gmail.com> wrote:
> On Jun 4, 10:28 pm, DIOS <sindi...(a)gmail.com> wrote:
>
>
>
> > On Jun 4, 2:09 pm, Onur Güzel <kimiraikkone...(a)gmail.com> wrote:
>
> > > On Jun 4, 9:58 pm, DIOS <sindi...(a)gmail.com> wrote:
>
> > > > VB2005 - I have a DataGridView with cells of various background colors
> > > > set with various methods. In the end I want to determine a color for
> > > > an individual cell, ie what the user sees. According to MSDN there is
> > > > a hierarchy of how the cell gets colored. Is there one function that
> > > > will get me the "final" color or do i have to step through the entire
> > > > DataGridViewCellStyle Class?
>
> > > > AGP
>
> > > Doesn't this work:
>
> > > ' Set desired color from Color structure
> > > DataGridView1.Item(Column, Row).Style.BackColor = Color
>
> > > or
>
> > > DataGridView1.CurrentCell.Style.BackColor = Color
>
> > > HTH,
>
> > > Onur Güzel
>
> > Sure it does. that's not my problem though. Let me restate,
> > In my processing I color the cells of the DGV using various
> > methods...rowstyle, cell style, etc.
> > I present that to the user. Now they click on a cell and i need to
> > determine the color that they see, the final color of the cell.
> > Because of the hierarchy of the DataGridViewCellStyle Class simply
> > using "If CurrentCell.Style.BackColor = Color.Red" will not work.
> > The cell will be colored red but its another style that set it.
> > According to MSDN they have a hierarchy of what is used to color the
> > cell.
> > My question is rather than cycling through all the class properties to
> > get to the final color that the user sees is there a super function
> > that
> > gives me the final rendered cell color? I'm interested in how to read
> > the final color of the cell.
>
> > AGP
>
> I may not have understood your question well because of the word
> "final" (what you meant), but my consideration is that you can store
> the color in a variable after user selected the color like that:
>
> ' Declare myColor as a global variable at class-level
> Dim myColor As Color
>
> Handle CellStyleContentChanged Event and inside:
>
> Private Sub DataGridView1_CellStyleChanged _
> (ByVal sender As System.Object, ByVal e As
> System.Windows.Forms.DataGridViewCellStyleContentChangedEventArgs)
> Handles DataGridView1.CellStyleContentChanged
>
> myColor = e.CellStyle.BackColor
>
> End Sub
>
> Retrieve "final" color when you want by means of myColor.
> "myColor" gets updated on every raise of CellStyleContentChanged
> event. (eg: Msgbox(myColor.toString))
>
>  HTH,
>
> Onur Güzel

Suppose you have a grid of 1000 x 1000. I don't think you want to save
the color into a variable for each and every cell. simply if I want to
get the color of cell @ row=3, column =5 i was hoping there was a
function that would cycle through all the DataGridViewCellStyle Class
properties to get me the rendered color. Right now in some areas of my
grid I color the entire row with
dgv.Rows(r).DefaultCellStyle.BackColor.= Color.Red. Now If i randomly
pick a cell and use dgvCell.Style.BackColor and it just happens to be
on that row i get a Color.Empty. My dilemma is with so many ways to
color a cell, i need a call that will always give me the color that is
rendered to the user.

AGP
 | 
Pages: 1
Prev: User ID and Logon for Database
Next: Image index.