Sunday, January 2, 2011

CDC Software Pivotal CRM 6.0: How to change rows style in PivotalSearchResultGrid

Here is an example we can access to PivotalSearchResultsGrid rows.
Lets color all rows that contain specific Company_Name value.
First of all we need to add DataBindingComplete event handler to the PivotalSearchResultsGrid control.
To do it we need to override OnFormInitialized method that fires after the form has been drawn and all the data has been loaded and bound:

public override void OnFormInitialized()
{
    PivotalSearchResultsGrid mySearchResultsGrid =   this.FormControl.GetControlByName("CompaniesPivotalSearchResultsGrid") as PivotalSearchResultsGrid;
    if (mySearchResultsGrid != null)
    {
        //Get a grid control from the PivotalSearchResultsGrid
        DataGridView grid = mySearchResultsGrid.ResultsViewControl.Controls[0].Controls[0] as DataGridView;
        //Handle DataBindingComplete event that fires when the content DataSource changed
        grid.d.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(dataGridView1_DataBindingComplete);
    }
}

Than just implement the dataGridView1_DataBindingComplete event handler:

private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
    DataGridView grid = sender as DataGridView;
    for (int i = 0; i < grid.Rows.Count; i++ )
    {
        DataGridViewRow row = grid.Rows[i];
        //Access to row data
        string companyName = row.Cells["Company_Name"].Value.ToString();
        if (companyName == "Microsoft")
        {
            //Paint row in Blue
            row.DefaultCellStyle.BackColor = Color.Blue;
        }
    }
}

Thats all.
Enjoy with Pivotal 6.0.

Saturday, January 1, 2011

CDC Software Pivotal 6.0: How to prevent to open record on double click in PivotalSearchResultsGrid control.



This is the way to remove an original CellMouseDoubleClick event handler to prevent to open records on double click in PivotalSearchResultsGrid.


Add CdcSoftware.Ios.dll reference to you Client Task project. 
Add DisableSearchResultGridDoubleClick function call in your Client Task in OnFormInitialized handler:


public override void OnFormInitialized()
{
 PivotalSearchResultsGrid clientDetectionSearchResultsGrid = this.FormControl.GetControlByName("ClientDetectionPivotalSearchResultsGrid") as PivotalSearchResultsGrid;
 if (clientDetectionSearchResultsGrid != null)
 {
  DisableSearchResultGridDoubleClick(clientDetectionSearchResultsGrid);
 }
}

private void DisableSearchResultGridDoubleClick(PivotalSearchResultsGrid grid)
{
 if (grid != null)
        {
         FieldInfo eventHandlerInfo = grid.ResultsViewControl.GetType().GetField("CellMouseDoubleClick", BindingFlags.NonPublic | BindingFlags.Instance);
                object oHandler = eventHandlerInfo.GetValue(grid.ResultsViewControl);

                EventHandler<cdcsoftware.iaf.ios.messaging.iafmessageeventargs> eventHandler = oHandler as EventHandler<cdcsoftware.iaf.ios.messaging.iafmessageeventargs>;

                if (eventHandler != null)
                {
                    grid.ResultsViewControl.CellMouseDoubleClick -= eventHandler;
                }
            }
        }
}