Exemple #1
0
        private static void selectTopItem(object s)
        {
            PropertyGrid propertyGrid = (PropertyGrid)s;

            if (!propertyGrid.IsHandleCreated)
            {
                return;
            }
            propertyGrid.BeginInvoke(new MethodInvoker(() =>
            {
                if (propertyGrid.IsDisposed)
                {
                    return;
                }

                // get selected item
                GridItem gi = propertyGrid.SelectedGridItem;
                if (gi != null)
                {
                    // get category for selected item
                    GridItem pgi = gi.Parent;
                    if (pgi != null && gi.Parent.Parent != null)
                    {
                        pgi = gi.Parent.Parent;
                    }
                    if (pgi != null)
                    {
                        //sort categories
                        List <GridItem> sortedCats = new List <GridItem>(pgi.GridItems.Cast <GridItem>());
                        sortedCats.Sort(delegate(GridItem gi1, GridItem gi2) { return(gi1.Label.CompareTo(gi2.Label)); });

                        // loop to first category
                        for (int i = 0; i < pgi.GridItems.Count; i++)
                        {
                            if (pgi.GridItems[i] == gi)
                            {
                                break; // in case full circle done
                            }
                            // select if first category
                            if (pgi.GridItems[i].Label == sortedCats[0].Label)
                            {
                                pgi.GridItems[i].Select();
                                break;
                            }
                        }
                    }
                }
            }));
        }
 public void Update()
 {
     _editControl.BeginInvoke(new Action(() => _editControl.Refresh()));
 }