private void MoveItem(int direction)
        {
            // Calculate new index using our direction.
            int index = lvFavorites.SelectedIndex + direction;

            // Check if we can move in that direction.
            if (index < 0 || index > lvFavorites.Items.Count)
            {
                return;
            }

            // Add our object to an ICollection.
            List <FavoriteObject> f  = new List <FavoriteObject>();
            FavoriteObject        fo = lvFavorites.SelectedObject as FavoriteObject;

            f.Add(fo);

            // Remove our collection.
            lvFavorites.RemoveObjects(f);

            // Insert our collection at the new index.
            lvFavorites.InsertObjects(index, f);

            // Set the focus to the new index.
            foreach (FavoriteObject x in lvFavorites.Objects)
            {
                if (fo.Name == x.Name)
                {
                    lvFavorites.SelectedObject = x;
                    break;
                }
            }
            lvFavorites.Focus();
            //lvFavorites.SetObjects(f);
        }
Exemple #2
0
 public frmEdit(FavoriteObject f, ObjectListView o)
 {
     InitializeComponent();
     fav          = f;
     mod          = o;
     txtName.Text = f.Name;
     txtData.Text = f.Data;
 }
        private void PopulateList()
        {
            List <FavoriteObject> favorites = new List <FavoriteObject>();

            for (int i = 0; i < SettingsManager.favorites.Count; i++)
            {
                string         name = SettingsManager.favorites.ElementAt(i).Key;
                string         data = SettingsManager.favorites.ElementAt(i).Value;
                FavoriteObject f    = new FavoriteObject(name, data);
                favorites.Add(f);
            }
            lvFavorites.AddObjects(favorites);
        }
 private void btnEdit_Click(object sender, EventArgs e)
 {
     if (lvFavorites.Items.Count > 0)
     {
         if (lvFavorites.SelectedObject != null)
         {
             FavoriteObject f    = lvFavorites.SelectedObject as FavoriteObject;
             frmEdit        edit = new frmEdit(f, lvFavorites);
             edit.ShowDialog();
         }
         else
         {
             MessageBox.Show("There isn't a selected favorite to edit.", " Sharp Scanner", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
     else
     {
         MessageBox.Show("There are no favorites. Try adding some.", " Sharp Scanner", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }