Пример #1
0
        private void chartControl1_ObjectSelected(object sender, HotTrackEventArgs e)
        {
            SeriesPoint seriesPoint = e.HitInfo.SeriesPoint;

            if (seriesPoint != null)
            {
                string[] values = seriesPoint.Argument.ToString().Split(new string[] { " | " }, StringSplitOptions.None);
                List <PivotGridField> fields = new List <PivotGridField>();

                pivotGridControl1.CollapseAll();
                //return;
                foreach (PivotGridField pivotGridField in pivotGridControl1.Fields)
                {
                    if (pivotGridField.Area == PivotArea.RowArea || pivotGridField.Area == PivotArea.ColumnArea)
                    {
                        fields.Add(pivotGridField);
                    }
                }

                // Expand field values
                for (int i = 0; i < values.Length; i++)
                {
                    PivotGridField fieldToExpand = GetFieldByAreaIndex(fields, i);

                    if (fieldToExpand == null)
                    {
                        continue;
                    }

                    if (Microsoft.VisualBasic.Information.IsNumeric(values[i]))
                    {
                        if (fieldToExpand.DataType == typeof(Int32))
                        {
                            fieldToExpand.ExpandValue(Int32.Parse(values[i]));
                        }
                        else if (fieldToExpand.DataType == typeof(Double))
                        {
                            fieldToExpand.ExpandValue(Double.Parse(values[i]));
                        }
                    }
                    else if (Microsoft.VisualBasic.Information.IsDate(values[i]))
                    {
                        fieldToExpand.ExpandValue(DateTime.Parse(values[i]));
                    }
                    else
                    {
                        fieldToExpand.ExpandValue(values[i].ToString());
                    }
                }
                //return;
                // Make cells selection
                List <Point> selectedCells = new List <Point>();
                int          lastIndex     = values.Length - 1;

                System.Threading.Thread.Sleep(100);
                for (int i = 0; i < pivotGridControl1.Cells.RowCount; i++)
                {
                    bool skipFlag = false;
                    for (int j = 0; j < values.Length; j++)
                    {
                        object value = pivotGridControl1.GetFieldValue(GetFieldByAreaIndex(fields, j), i);

                        if (!object.Equals(value, values[j]))
                        {
                            skipFlag = true;
                        }
                    }

                    if (skipFlag)
                    {
                        continue;
                    }

                    for (int j = 0; j < pivotGridControl1.Cells.ColumnCount; j++)
                    {
                        selectedCells.Add(new Point(j, i));
                    }
                }

                if (selectedCells.Count != 0)
                {
                    pivotGridControl1.Cells.FocusedCell = selectedCells[0];
                    pivotGridControl1.Cells.MultiSelection.SetSelection(selectedCells.ToArray());
                }
            }
        }