//protected override void Cell_PropertyChanged(object sender, PropertyChangedEventArgs e)
        //{

        //    if (e.PropertyName.Equals("HasMouseFocus"))
        //    {
        //        bool hasMouseFocus = ((GnosisResultsGridFieldController)sender).HasMouseFocus;
        //        foreach (GnosisResultsGridFieldController child in Fields)
        //        {
        //            child.HasRowMouseFocus = hasMouseFocus;
        //        }
        //        GlobalData.Singleton.ParentWindowImplementation.WriteToWindow("HasRowMouseFocus - " + rowNum.ToString());
        //    }

        //    base.Cell_PropertyChanged(sender, e);
        //}

        //public override void AddCell(IGnosisGridFieldImplementation resultsFieldImp)
        //{
        //    base.AddCell(resultsFieldImp);

        //    //((IGnosisResultsFieldImplementation)gridFieldImp).SetGotMouseFocusHandler(new Action(OnGotMouseFocus));
        //    //((IGnosisResultsFieldImplementation)gridFieldImp).SetLostMouseFocusHandler(new Action(OnLostMouseFocus));
        //    //((IGnosisResultsFieldImplementation)gridFieldImp).SetMouseDownHandler(new Action(OnMouseDown));
        //    //((IGnosisResultsFieldImplementation)gridFieldImp).SetMouseUpHandler(new Action(OnMouseUp));
        //    resultsFieldImp.PropertyChanged += ResultsFieldImp_PropertyChanged;
        //}

        protected override void GridFieldImp_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.GridFieldImp_PropertyChanged(sender, e);

            IGnosisResultsFieldImplementation resultsField = sender as IGnosisResultsFieldImplementation;

            switch (e.PropertyName)
            {
            case "HasMouseFocus":
                if (resultsField.HasMouseFocus)
                {
                    OnGotMouseFocus();
                }
                else
                {
                    OnLostMouseFocus();
                }
                break;

            case "HasMouseDown":
                if (resultsField.HasMouseDown)
                {
                    OnMouseDown();
                }
                else
                {
                    OnMouseUp();
                }
                break;
            }
        }
        public override void CreateFields()
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            rowControllers = new Dictionary <int, GnosisGridRowController>();
            string datasetName = ((GnosisGrid)ControlImplementation).Dataset;
            int    rowNo       = 0;

            if (InstanceController != null)
            {//if1
                IEnumerable <XElement> dataRows = InstanceController.GetDataRows(datasetName);

                if (dataRows == null || dataRows.Count() == 0)
                {//if2
                    return;
                }//if2

                fieldsCreated = true;
                var orderedColumns = columns.OrderBy(c => c.Order);

                foreach (var row in dataRows)
                {//foreach2
                    GnosisResultsRowController rowController = new GnosisResultsRowController(this, rowNo);
                    rowControllers.Add(rowNo, rowController);

                    foreach (GnosisGridColumnController column in orderedColumns)
                    {//foreach3
                        IGnosisResultsFieldImplementation resultsField = (IGnosisResultsFieldImplementation)column.GetFieldClone();

                        string attributeName = InstanceController.GetTargetAttributeName(column.Dataset, column.DatasetItem);
                        string attribute     = "";
                        if (row.Attribute(attributeName) != null)
                        {
                            attribute = row.Attribute(attributeName).Value;
                        }

                        if (column.ColumnModel is GnosisTextResults) //(column.ColumnType.Equals(ControlTypeMapping.GetControlTypeName(typeof(GnosisTextColumn))))
                        {                                            //if4
                            if (!attribute.Equals(""))
                            {
                                ((IGnosisResultsTextFieldImplementation)resultsField).SetText(attribute);
                            }
                        }//if4
                        else if (column.ColumnModel is GnosisCheckResults)
                        {
                            if (!attribute.Equals(""))
                            {
                                bool val = false;
                                if (attribute.Equals("1"))
                                {
                                    val = true;
                                }
                                ((IGnosisResultsCheckFieldImplementation)resultsField).GnosisChecked = val;
                            }
                        }

                        rowController.AddCell(resultsField);
                    }//foreach3

                    rowNo++;
                } //foreach2
            }     //if1

            stopWatch.Stop();
            Debug.WriteLine("GnosisSearchResultsGridController, CreateFields, Milliseconds elapsed: {0}", stopWatch.ElapsedMilliseconds);         stopWatch.Stop();
        }