11/30/2024 4:35:29 AM
|
|
slxdeveloper.com Community Forums |
|
|
|
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
Forum to discuss usage & tips for SalesLogix controls and other 3rd party ActiveX controls. View the code of conduct for posting guidelines.
|
|
|
|
DataGrid OnCustomDrawCell Primer needed please
Posted: 19 Nov 07 11:04 AM
|
I can change the font, fontcolor etc. on rows....selected rows.....if a value in a row exceeds a certain criterion.....
But am really failing on what a node is versus what's selected versus what the rows are.....
There is a NODES and COLUMN class/object that's returned with the OnCustomDrawCell call/method that's not in Sender/the Data Grid......
does anyone have a better example of how to utilize the Cell by Cell (Column), Row by Row (Node) method ???
Sub dgOppProductsCustomDrawCell(Sender, ByRef Node, ByRef Column, IsSelected, IsFocused, ByRef Text, ByRef Color, ByRef Alignment, ByRef Font, ByRef FontColor)
HELP PLEASE!!!???
Thanks
RJ Samp
|
|
|
|
Re: DataGrid OnCustomDrawCell Primer needed please
Posted: 20 Nov 07 8:42 AM
|
Hi RJ Samp,
How do you set fontcolor for a row at runtime?? I have a datagrid which I am populating at runtime. I need to change color on some rows, depending on a bool condition.
Thx. |
|
|
|
Re: DataGrid OnCustomDrawCell Primer needed please
Posted: 20 Nov 07 9:43 AM
|
Sub dgOppProductsCustomDrawCell(Sender, ByRef Node, ByRef Column, IsSelected, IsFocused, ByRef Text, ByRef Color, ByRef Alignment, ByRef Font, ByRef FontColor)
If Column.NAME = "PRICE" OR COLUMN.NAME = "A2_PRICE" THEN IF ISNUMERIC(TEXT) THEN DIM ThePrice ThePrice = cDBL(TEXT) If ThePrice < 100 THEN fontcolor = rgb(0,0,0) '''BLACK ELSE fontcolor = application.basicfunctions.StringToColor("Red") '''''I think this works, if not: fontcolor = rgb(200,0,0) '''Red fontcolor = rgb(0,150,0) '''Lime Green END IF END IF END SUB
the Grid oncustomdrawcell is called for EACH cell in the grid, everytime a refresh is called... your subroutine is changing the parameters in the Subroutine itself! So COLOR is the cell background color.....
To change the entire ROW, then you need to know which Row you are on (which is my QUESTION), and then change EACH CELL in the row.... |
|
|
|
Re: DataGrid OnCustomDrawCell Primer needed please
Posted: 20 Nov 07 10:34 AM
|
Thanks RJ.
I wanted to avoid OnCustomeDrawCell method... it's not the most performant one. I was thinking maybe there is a way to do DataGrid.Row(i).FontColor = vbRed or something more simpler.... Anyway, I will use OnCustomeDrawCell for now and if I find a better way to do it I will let you know.
Thanks again. |
|
|
|
Re: DataGrid OnCustomDrawCell Primer needed please
Posted: 29 Nov 07 11:11 AM
|
OK......progress made. 1. Very intensive processing for the Screen Painting/repainting function. It calls for a redraw of every cell in every node for a simple mouse MOVEMENT of one pixel.
2. Never put a MSGBOX in the function.....it will fire OFTEN.
3. ISFOCUSED means mouse over the grid....that means it fires/is true LOTS of the time.
4. Node has lots of neat stuff in it.....including the valueS of every cell on that row....in Grid Column order..... ROWID = node.Values(position in Grid....possibly 0 for the first position).
5. Set an ID value for the row everytime you change nodes (that's a grid event). Say WorkingOnID
6. In the custom draw event, get the rowid being processed , e.g. ROWID = node.Values(0) and then compare it to what you want to work on.....or copy ..... or paste.....or calculate....or recolor If WorkingOnID = ROWID THEN COLOR = rgb(,,) FONTCOLOR = rgb(,,) etc. END IF This way you can work on an entire row...... If you want to work on a specific CELL..... If WorkingOnID = ROWID THEN IF Node.Index = 4 THEN COLOR = rgb(,,) FONTCOLOR = rgb(,,) ELSE
END IF etc. END IF
Keep it simple, this is Processor intensive....
|
|
|
|
Re: DataGrid OnCustomDrawCell Primer needed please
Posted: 29 Nov 07 12:17 PM
|
awesome ! makes sense...
thanks !
one question though... is it true that in your case CustomDraw Event will be called every time when you do someting on the grid: click, resize... etc, right? ... but it will increase performace becuase watever I am processing inside it will be called just once a line. Did I get it right? one more thing... my changes/colors are not user event driven. I am comparing values from 2 datasets.
|
|
|
|
Re: DataGrid OnCustomDrawCell Primer needed please
Posted: 29 Nov 07 1:14 PM
|
It is called often...so put an IF statement on every action you want to potentially change the colors on..... It's called against EVERY CELL and EVERY NODE.
I would set a COMPARE Flag for the two datasets, and initially set COMPARE = FALSE....when they click on a COMPARE BUTTON then set the Compare to True and you could run a refresh on the dataset that you want force the Custom Draw event......
SO
DIM COMPARE SUB AXFORMCHANGE COMPARE = FALSE grid1.REFRESH grid2.REFRESH END SUB
SUB OnCustomDraw IF COMPARE THEN IF dataset1 value <> dataset2 value start coloring END IF END SUB
SUB CMDCOMPAREButtonClick COMPARE = TRUE END SUB
I don't know how you would RESET COMPARE to False......maybe when the click somewhere else? If they hover over the grid, oncustomdraw will continue to fire......
Anyway, OnCustomDraw fires every time you do a refresh (which you can call programmatically dgname.REFRESH)....as well as any user event that 'touches' the grid. |
|
|
|
Re: DataGrid OnCustomDrawCell Primer needed please
Posted: 30 Nov 07 4:08 PM
|
I think OnCustomDraw runs even if anything passes over it - you don't even need to touch it. That's a major reason why I really laughed out loud on advice number 2 - No Message boxes. I tried that, and I thought if I sit there and click them away they would disappear, but they kept popping up over the grid and causing it to redraw! Needless to say, I was rescued by Windows Task Manager.
Anyway, I just discovered how to use the node thing two days ago myself. I have a grid that shows both payments and refunds (for the accounts an ISE made a sale on), and I wanted to highlight any line that was a refund with a light redish color. I finally did a search for CustomDrawCell in all the plugins, and one of them showed how to use the node thing. I think it is quite nice as well - you can access any value of that node/row on for any cell that is being drawn on that node. So, for any cell where node.value("Action") = "Refund", I assign the rgb color for the light redish color, and that highlights the rows for the refunds.
It's nice to finally know how the event works... |
|
|
|
Re: DataGrid OnCustomDrawCell Primer needed please
Posted: 01 Dec 07 12:13 AM
|
Here's an example that will make it easier for future:
================ Colouring a grid ================
For the Grid - select the property "OnCustomDrawCell" - this will create a sub based on the name of the grid followed by CustomDrawCell e.g. --------------|-------------| Sub dgServicesCustomDrawCell(Sender, ByRef Node, ByRef Column, IsSelected, IsFocused, ByRef Text, ByRef Color, ByRef Alignment, ByRef Font, ByRef FontColor)
Dim sFieldName Dim vStatus Dim lColumnIndex
sFieldName = UCase ( Column.FieldName ) ' Field you want to look for
Select Case sFieldName Case "A2_STATUS" ' ALIAS name of the column in QB lColumnIndex = GetColumnIndexByFieldName ( dgServices,"A2_STATUS" ) ' Used so that grid can be sorted/grouped vStatus = Node.Values ( lColumnIndex ) ' Gets the actual value End Select
If Not IsNull ( vStatus ) Then ' Ensure you check for Nulls
Select Case vStatus Case "Open" FontColor = &H00000000 ' in v7.x - you can use enum of clBlack, clGreen etc Case "Lost" FontColor = &H000000FF Case "Won" FontColor = &H00800000 Font.Bold = True End Select End If
End Sub
'========================================================================================== Function GetColumnIndexByFieldName ( ByRef Grid, ByVal FieldName ) Dim i Dim lColumnIndex
lColumnIndex = -1 For i = 0 To Grid.Columns.Count - 1 If UCase ( Grid.Columns(i).FieldName ) = UCase ( FieldName ) Then lColumnIndex = i Exit For End If Next GetColumnIndexByFieldName = lColumnIndex End Function |
|
|
|
Re: DataGrid OnCustomDrawCell Primer needed please
Posted: 08 Jan 08 5:27 PM
|
Hi Mike,
Thanks for the exmple. Very clear and easy to implement.
What about if I want to color a row depending on a hidden value of the grid? Can I do that?
For example, I have the following columns to be displayed in a grid
Account, Adress, City, State....
To save some space on the grid, if any account has a Legal Issue than I want to color the row in red, instead of displaying a checkbox for this field. I do not want to display LegalIssue field in the datagrid.
|
|
|
|
You can
subscribe to receive a daily forum digest in your
user profile. View the site code
of conduct for posting guidelines.
Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
|
|
|
|
|
|
|
|