Skip to main content Skip to footer

Magic Of HitTest in OLAP

ComponentOne OLAP for WinForms helps to create interactive tables, charts, and reports. The C1OlapGrid contained within the C1OlapPage control extends the C1FlexGrid control, our general-purpose grid control. This means the whole C1FlexGrid object model is also available to C1Olap users. With this blog, we will provide customizations in C1Olap via ‘HitTest‘ method of C1FlexGrid.

Custom Details View Dialog

The default Details View Dialog displays the cell information in the C1OlapGrid within the C1OlapPage by right clicking a particular cell in grid. This dialog could be customized with the help of 'HitTest' method and the information relevant to a particular user scenario could be displayed. Here is how the dialog could be customized :

//Get Clicked Data on the BeforeMouseDown event of the grid  
\_c1OlapPage.OlapGrid.BeforeMouseDown += (\_s, _e) =>  
{  
//check if the cell is right clicked   
if (\_e.Button == MouseButtons.Right && \_e.Clicks > 0)  
{  
    //store the HitTest information in a variable 'hti'  
    C1.Win.C1FlexGrid.HitTestInfo hti = \_c1OlapPage.OlapGrid.HitTest(\_e.X, _e.Y);  
    // make sure we are working with a cell  
    if (hti.Type == C1.Win.C1FlexGrid.HitTestTypeEnum.Cell)  
    {  
        // get data using OlapEngine  
        var data = \_c1OlapPage.OlapEngine.GetDetail((\_c1OlapPage.OlapGrid.Rows[hti.Row].DataSource as DataRowView).Row, _c1OlapPage.OlapEngine.OlapTable.Columns[0].ColumnName);  
        Form f = new Form();  
        f.Size = new Size(400, 250);  
        f.StartPosition = FormStartPosition.CenterParent;  
        f.Text = "Customized Detail View : " + data.Count.ToString() + " records";  
        C1.Win.C1FlexGrid.C1FlexGrid flex = new C1.Win.C1FlexGrid.C1FlexGrid();  
        flex.Dock = DockStyle.Fill;  
        flex.DataSource = data;  
        f.Controls.Add(flex);  
        //display the custom dialog form  
        f.ShowDialog();  
    }  
}  

};

Copy information from the Row Headers

The Information displayed on the Fixed columns of the C1OlapGrid is not accessible as such. However, there can occur a need to use this information. We can again make use of the 'HitTest' method here to access that information from the Row Headers of the C1OlapGrid. For doing this, we will make use of the Clipboard object to store the information copied from the row headers and then this could be pasted and used in particular user scenarios. To copy this information from the RowHeaders of the grid, we will employ a cotextmenustrip on the grid. Here is how this could be done :

//Get Clicked Data on the BeforeMouseDown event of the grid  
\_c1OlapPage.OlapGrid.BeforeMouseDown += (\_s, _e) =>  
{  
//check if the cell is right clicked   
if (\_e.Button == MouseButtons.Right && \_e.Clicks > 0)  
{  
    //store the HitTest information in a variable 'hti'  
    C1.Win.C1FlexGrid.HitTestInfo hti = \_c1OlapPage.OlapGrid.HitTest(\_e.X, _e.Y);  

    // make sure we are working with the row header  
    if (hti.Type == HitTestTypeEnum.RowHeader)  
    {  
        //assign a contextmenustrip to the olapgrid  
        _c1OlapPage.OlapGrid.ContextMenuStrip = contextMenuStrip1;  
        //get the row header text in some variable 'clickeddata'   
        clickeddata = \_c1OlapPage.OlapGrid.GetData(\_c1OlapPage.OlapGrid.MouseRow, _c1OlapPage.OlapGrid.MouseCol).ToString();  
    }  
}  

};  

//handle the click event of the 'Copy' menu item on the contextmenustrip  
private void copyMenuItem1_Click(object sender, EventArgs e)  
{  
    try  
    {  
        //store the captured data from 'clickeddata' in a clipboard object  
        _c1OlapPage.OlapGrid.ClipboardCopyMode = ClipboardCopyModeEnum.DataOnly;  
        Clipboard.SetData(System.Windows.Forms.DataFormats.StringFormat, clickeddata);  
    }  
    catch(Exception ex)  
    {  
        //display the error message  
        MessageBox.Show(ex.Message);  
    }  
}  

Olap_Hittest Many more customizations like this are possible in C1Olap. We are open to your suggestions and requirements :) Download Sample CS Download Sample VB

MESCIUS inc.

comments powered by Disqus