Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
605
how to do conditional formatting based on measure name
posted

Hi, In the samples for conditional formatting they use the column index to decide what style to apply, eg:

int column = this.pivotGrid.DataColumns.IndexOf(e.Cell.DataColumn);

int row = this.pivotGrid.DataRows.IndexOf(e.Cell.DataRow);

 if (this.pivotGrid.DataSource.Result != null && column == 0) { ... }

The problem is if you change the order of your measuers then the formatting still applies to whatever measure lives in the first column, and this may not be applicable.  I'd like to style to follow the measure in whichever column the user situates it.  So the code should use the column name somehow, surely this must be possible?

Notice the 2 examples below, the short column should always be in red, but if I move it then the net column is in red.

 

  • 7922
    Verified Answer
    posted

    Hi

     

    In pointed example the style is applied to cells in column with index 2. The column index is not related with measure. If you drop complex hierarchy there will be more columns than measures.

     

    To find relation between column and measure which generate data in this column you can use code below

     

    IMeasureListViewModel measureListViewModel = pivotGrid.DataSource.MeasureListViewModel;

    int measureListIndex = 0;

       

    // check if we have more than 1 measure droped

    if (measureListViewModel != null)

    {

        // find out measure index.

        if (pivotGrid.DataSource.MeasureListLocation == MeasureListLocation.Rows)

        {

            measureListIndex = pivotGrid.DataSource.Rows.IndexOf(measureListViewModel);

        }

        else

        {

            measureListIndex = pivotGrid.DataSource.Columns.IndexOf(measureListViewModel);

        }

    }

     

    // We assume that the measures are in columns. 

    int columnIndex = this.pivotGrid.DataColumns.IndexOf(e.Cell.DataColumn)

    ITuple tuple = this.pivotGrid.DataSource.Result.ColumnAxis.Tuples[columnIndex];

    IMember measureMember = tuple.Members[measureListIndex];

    IMeasureViewModel measureViewModel = pivotGrid.DataSource.Measures.FirstOrDefault(m => ((IMeasureViewModel)m).Measure.UniqueName == measureMember.UniqueName);

    IMeasure lookupMeasure = measureViewModel.Measure;

    if(lookupMeasure.Caption == "Short")

    {

        //Aplly cell's style

    }

     

    Regards

    Todor