Login / Register  search  syndication  about

          Kris Halsrud's Blog

Kris Halsrud on development and Integration with CRM and Development

Formatting a datagrid's cells to have custom colors in the SalesLogix LAN client

A client recently posed a question to me regarding if you can customize the SalesLogix grid in the LAN client to have coloring applied based upon conditions.  The answer is yes you can.  lets take a look at how.

The SalesLogix data grid control has an event called OnCustomDrawCell.  This event has several arguments that are passed in including:

  • Sender- the grid control
  • Node- The row in the grid
  • Column- The column being rendered
  • IsSelected- A boolean expressing if the cell is selected
  • IsFocused- A boolean expressing if the cell is currently in focus
  • Text- Writable property relating to the text displayed in the grid
  • Color- Writable property relating to the background color of the cell displayed in the grid
  • Alignment- Writable property relating to the text alignment in the grid 
  • Font- Writable property relating to the text's font displayed in the grid
  • FontColor- Writable property relating to the text's color displayed in the grid

Lets take a look at how we might examine the contents of a given row, and then based on that information do something to another cell:

Sub grdContactsCustomDrawCell(Sender, ByRef Node, ByRef Column, IsSelected, IsFocused, ByRef Text, ByRef Color, ByRef Alignment, ByRef Font, ByRef FontColor)
Dim sFieldName
Dim vName
Dim lColumnIndex
Dim vID

    sFieldName = UCase(Column.FieldName) ' Field you want to look for

    Select Case sFieldName
        Case "ISPRIMARY" ' ALIAS name of the column in QB
            lColumnIndex = GetColumnIndexByFieldName ( grdContacts,"NAMELF" ) ' Used so that grid can be sorted/grouped
            vName = Node.Values ( lColumnIndex ) ' Gets the actual value           

        If Not IsNull ( vName ) Then ' Ensure you check for Nulls   

            Select Case ucase(left(vName,1))
                Case "A"
                Color = rgb(255,0,0)
                Font.Bold = True
                FontColor = rgb(0,255,0)
            End Select
        End If
    End Select
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

In the code above we have a case statement that is looking to see if the column of the cell being rendered is the "ISPRIMARY" column. 

    Select Case sFieldName
        Case "ISPRIMARY" ' ALIAS name of the column in QB
            lColumnIndex = GetColumnIndexByFieldName ( grdContacts,"NAMELF" ) ' Used so that grid can be sorted/grouped
            vName = Node.Values ( lColumnIndex ) ' Gets the actual value           
   

If it is it then uses the function GetColumnIndexByFieldName which retruns the column index of a different column we want to find.  In this example we re finding the index position of the "NAMELF" column.  With that index position identified we can then use the Node.Values() function to fetch the value in the column index position specified.

With the Name value having been captured, we can then do something with with it.  In our example we are looking to see if it starts with "A".  if it does then we are setting things like the Color, Font.Bold, and FontColor.

The end result is a grid with color coding:

 

One last thing.  Suppose you want to get data related to the record but not necessarily in the grid.  Well if you want to get the ID of the record that is being rendered you can use something like this:

 vID = sender.GetCurrentField(sender.KeyField) 'Gets the primary keyfield of the current row.

 Note: this code does run per cell that is rendered so it can increase the time to render the grid, especially if you are loading a grid with lots of records.

 

What's This?
  
Bookmark and Share

About Kris Halsrud

   Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.


Related Content
   Saleslogix XBar Installation
When installing the new XBar application I found the instructions a little vague so I thought I would pas
Posted on Jul 18, 2014 by Mark Duthoy to SalesLogix Support
 
   "Saleslogix’s affordable pricing and usability allow the product to rise above competitors in the space" - Info-Tech Research Group, Inc.
"SalesLogix’s affordable pricing and usability allow the product to rise above competitors in the sp
Posted on Jul 14, 2014 by Scott Weber to SalesLogix Product Blog
 
   Saleslogix Default Group Layout
How can I default the formatting of columns in my Saleslogix groups?
Posted on Jul 03, 2014 by Dale Richter to SalesLogix Questions & Answers
 
   Changing Contact Process Statuses in Bulk
Recently, I was asked if it was possible to cancel a group of running contact processes.The answer is yes
Posted on Jun 30, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
   Finding the Current Parent Record ID in SalesLogix Web
Sometimes it's the easiest things that can be a big barrier to entry for getting started with somet
Posted on Jun 27, 2014 by Ryan Farley to Ryan Farley's Blog
 
Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add
All contents Copyright © 2014 Customer FX Corporation
Customer FX Corporation
2324 University Avenue West, Suite 115
Saint Paul, Minnesota 55114
Tel: 800.728.5783

  Follow @CustomerFX on twitter
Follow the best news, tips, and articles
  Subscribe to Customer FX on youtube
Watch SalesLogix tutorial videos from Customer FX
Login / Register