We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Still Having Cell Color Problems

I tried coloring the rows like u told me but it calls the event of prepareview ... when ? anyway , it only colors me one row each time , i wanna color a row and after i add another row color it in other colors and after i add another row i color it in another color and so on and on . the rows will be colored according to the information in them . anyway when i try to use it , it only colors one row each time because it loses in the next time the event is read , the row he colored before , what can i do so it can save the rows that i already colored and add another row and color it too .. thanks a lot

7 Replies

AD Administrator Syncfusion Team November 6, 2003 06:53 AM UTC

The sample in the other forum thread had no problem coloring multiple rows, did it? What decides what rows you want to color? Do you have a list of these rows? Or, is there some value in the row that decides what needs to be colored? In the sample, there was a criteria set in PrepareViewStyleInfo, and any (and every) row that met this citteria was colored. In your PrepareViewStyleInfo, you must provide some criteria that decides whether a row is colored or not. So, in PrepareViewStyleInfo, your code must answer the question "Does e.RowIndex point to a row that needs to be colored?". If it does, then provide the color in e.Style.BackColor. Exactly how you answer this question is up to you and your requirements. One last comment is that when you change something that will change whether or not a row is to be colored, then you must trigger a redraw of the affected rows so that PrepareViewStyleInfo will be hit (which is what makes the coloring happen). So, for example, if you have an arraylist of colored rows which is used in PrepareViewStyleInfo to decide to color rows, and you add 4 to this Arraylist, then you would also want to call this.grid.RefreshRange(GridRangeInfo.Row(4)) to force that row to be redrawn (showing its color). This redraw step may be what you are presently omitting.


AN Andrew November 6, 2003 11:31 AM UTC

I also cannot get the color of my cell to stick. #Region "PrepareViewStyleInfo Event Functions" Private Sub Header_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As GridPrepareViewStyleInfoEventArgs) If e.ColIndex > 0 And e.RowIndex = 0 Then e.Style.BackColor = Color.AliceBlue End If End Sub This is in the form's load event: AddHandler grdResults.PrepareViewStyleInfo, AddressOf Header_PrepareViewStyleInfo AddHandler grdResults.PrepareViewStyleInfo, AddressOf RetailPrice_PrepareViewStyleInfo I also refresh the grid afterwards but nothing happens Andrew Private Sub RetailPrice_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As GridPrepareViewStyleInfoEventArgs) If e.ColIndex = 11 And e.RowIndex > 0 Then e.Style.CellType = "Currency" 'Set formatting properties grdResults(e.RowIndex, e.ColIndex).CurrencyEdit.CurrencyDecimalDigits = 2 grdResults(e.RowIndex, e.ColIndex).CurrencyEdit.CurrencyDecimalSeparator = "." grdResults(e.RowIndex, e.ColIndex).CurrencyEdit.CurrencyGroupSeparator = "," grdResults(e.RowIndex, e.ColIndex).CurrencyEdit.CurrencyGroupSizes = New Integer() {3} grdResults(e.RowIndex, e.ColIndex).CurrencyEdit.CurrencyNegativePattern = 1 grdResults(e.RowIndex, e.ColIndex).CurrencyEdit.CurrencyNumberDigits = 27 grdResults(e.RowIndex, e.ColIndex).CurrencyEdit.CurrencyPositivePattern = 0 grdResults(e.RowIndex, e.ColIndex).CurrencyEdit.CurrencySymbol = "$" grdResults(e.RowIndex, e.ColIndex).TextColor = System.Drawing.Color.Black grdResults(e.RowIndex, e.ColIndex).CurrencyEdit.NegativeColor = System.Drawing.Color.Red grdResults(e.RowIndex, e.ColIndex).CurrencyEdit.NegativeSign = "-" grdResults(e.RowIndex, e.ColIndex).CurrencyEdit.PositiveColor = System.Drawing.Color.Black End If End Sub #End Region


AD Administrator Syncfusion Team November 6, 2003 01:26 PM UTC

Attached is a sample using your first bit of code. It seems to work for me. Does it not work for you? A couple of comments though. Checking for e.RowIndex = 0 is picking out the column header row. Is this what you want? Your second PrepareViewStyleInfo will not work. As mentioned in those KB articles, you cannot use grid(row,col) to set any property other than Text (or CellValue). You cannot use it to set CurrencyEdit properties. So you code like grdResults(e.RowIndex, e.ColIndex).CurrencyEdit.CurrencyDecimalDigits = 2 should read e.Style.CurrencyEdit.CurrencyDecimalDigits = 2 But even changing all your grid(row, col) to e.Style's would not be a good idea. Generally, PrepareViewStyleInfo should only be used to set properties that are special to an individual cell or row. But not used to set column properties as you have in your sample code. Instead, you should use the GridBoundColumn.StyleInfo for that column to set column properties as explained in this kb. http://www.syncfusion.com/KB/Grid/Grid_c35c.asp#q562q The reason is that PrepareViewStyleInfo is hit a lot, and for performance considerations, you normally want to minimize the work you do there.


AN Andrew November 6, 2003 03:46 PM UTC

Thanks for the information, I will make the changes. However, the color code is not working. I want to change the color of the column header. Andrew > Attached is a sample using your first bit of code. It seems to work for me. Does it not work for you? > > A couple of comments though. Checking for e.RowIndex = 0 is picking out the column header row. Is this what you want? > > Your second PrepareViewStyleInfo will not work. As mentioned in those KB articles, you cannot use grid(row,col) to set any property other than Text (or CellValue). You cannot use it to set CurrencyEdit properties. So you code like > > grdResults(e.RowIndex, e.ColIndex).CurrencyEdit.CurrencyDecimalDigits = 2 > > should read > > e.Style.CurrencyEdit.CurrencyDecimalDigits = 2 > > > But even changing all your grid(row, col) to e.Style's would not be a good idea. Generally, PrepareViewStyleInfo should only be used to set properties that are special to an individual cell or row. But not used to set column properties as you have in your sample code. Instead, you should use the GridBoundColumn.StyleInfo for that column to set column properties as explained in this kb. > http://www.syncfusion.com/KB/Grid/Grid_c35c.asp#q562q > > The reason is that PrepareViewStyleInfo is hit a lot, and for performance considerations, you normally want to minimize the work you do there. > >


AD Administrator Syncfusion Team November 6, 2003 06:05 PM UTC

The attached sample does not work to show red colum headers for you? What version of our controls are you using? The sample showed red column headers with a private release version 1.6.1.9.


AN Andrew November 7, 2003 09:46 AM UTC

I tried the code snippet below: grdResults.GridBoundColumns("RetailPrice").StyleInfo.CellType = "Currency" This resulted in the entire Retail Price column turning red with the word "Exception" written in the cell. I have the DisplayEmptyRows option set to True, will this influence the behavior? Also, I still cannot get the color of my column header to change to AliceBlue. I put a break point in the event to make sure it's firing, which it is. It must be an issue with refreshing the grid. Where should I refresh the grid? grdResults.RefreshRange(GridRangeInfo.Row(0)) It always seems to fire before the PrepareViewInfoStyle event. Thanks, Andrew > The attached sample does not work to show red colum headers for you? > > What version of our controls are you using? The sample showed red column headers with a private release version 1.6.1.9. >


AD Administrator Syncfusion Team November 7, 2003 10:21 AM UTC

Can you post a sample project showing these problems? That will likely be the quickest way to get a resolution.

Loader.
Up arrow icon