Exemple #1
0
 public DataRow ReplaceSelected()
 {
     if (_target_list != null)
     {
         CurrentObjectTableView cotv = ControlList.schedule.Tables[_target_list] as CurrentObjectTableView;
         if (cotv == null)
         {
             MyListBox target_list = this.Parent.Controls[_target_list] as MyListBox;
             if (target_list != null)
             {
                 cotv = target_list.DataSource as CurrentObjectTableView;
             }
         }
         if (cotv != null)
         {
             if (this.SelectedItem != null)
             {
                 DataRowView drv = this.SelectedItem as DataRowView;
                 return(cotv.ReplaceChildMember(drv.Row, cotv.Current));
             }
         }
     }
     return(null);
 }
Exemple #2
0
        /// <summary>
        /// Adds selected item to a list.  Set target_list to the list to put the relation in.  That will provide the parent to relate under
        /// </summary>
        /// <returns></returns>
        public static DataRow AddSelected(ListBox listbox)
        {
            MyListBox myListbox = listbox as MyListBox;

            if (myListbox != null && myListbox._target_list != null)
            {
                CurrentObjectDataView  codv = null;
                CurrentObjectTableView cotv = ControlList.schedule.Tables[myListbox._target_list] as CurrentObjectTableView;
                if (cotv == null)
                {
                    ListBox target_listbox = listbox.Parent.Controls[myListbox._target_list] as ListBox;
                    if (target_listbox != null)
                    {
                        cotv = target_listbox.DataSource as CurrentObjectTableView;
                    }
                    if (cotv == null)
                    {
                        codv = target_listbox.DataSource as CurrentObjectDataView;
                    }
                }
                if (cotv != null || codv != null)
                {
                    if (listbox.SelectionMode == System.Windows.Forms.SelectionMode.MultiExtended ||
                        listbox.SelectionMode == System.Windows.Forms.SelectionMode.MultiSimple)
                    {
                        foreach (object item in listbox.SelectedItems)
                        {
                            if (cotv != null)
                            {
                                cotv.AddChildMember((item as DataRowView).Row);
                            }
                            else
                            {
                                codv.AddChildMember((item as DataRowView).Row);
                            }
                        }
                        return(null);
                    }
                    else if (listbox.SelectedItem != null)
                    {
                        DataRowView drv = listbox.SelectedItem as DataRowView;
                        if (cotv != null)
                        {
                            return(cotv.AddChildMember(drv.Row));
                        }
                        else
                        {
                            return(codv.AddChildMember(drv.Row));
                        }
                    }
                }
            }
            if (myListbox != null)
            {
                if (myListbox.AddCurrent != null)
                {
                    if (listbox.SelectedItem != null)
                    {
                        if (myListbox.allow_edit)
                        {
                            DataRowView drv = listbox.SelectedItem as DataRowView;
                            return(myListbox.AddCurrent(drv.Row));
                        }
                        else
                        {
                            MessageBox.Show("Editing is not enabled.");
                        }
                    }
                }
            }
            return(null);
        }
Exemple #3
0
        public static void RemoveSelected(ListBox listbox)
        {
            MyListBox myListbox  = listbox as MyListBox;
            bool      table_view = (listbox.DataSource as CurrentObjectTableView != null);

            if (myListbox == null || myListbox.allow_edit)
            {
                if (listbox.SelectionMode == System.Windows.Forms.SelectionMode.MultiSimple ||
                    listbox.SelectionMode == System.Windows.Forms.SelectionMode.MultiExtended)
                {
                    if (listbox.SelectedItems.Count == 0)
                    {
                        MessageBox.Show("No Selection");
                        return;
                    }
                    List <DataRow> rows_to_delete = new List <DataRow>();
                    foreach (object item in listbox.SelectedItems)
                    {
                        DataRowView tmp_item = item as DataRowView;
                        if (table_view)
                        {
                            rows_to_delete.Add(tmp_item.Row.GetParentRow(tmp_item.Row.Table.ParentRelations[0]));
                        }
                        else
                        {
                            rows_to_delete.Add(tmp_item.Row);
                        }
                    }

                    foreach (DataRow item in rows_to_delete)
                    {
                        if (myListbox != null && myListbox.DeleteSelection != null)
                        {
                            // foreach selected item?
                            myListbox.DeleteSelection(item);
                        }
                        item.Delete();
                    }
                }
                else
                {
                    if (listbox.SelectedItem == null)
                    {
                        MessageBox.Show("No Selection");
                        return;
                    }
                    int here = listbox.SelectedIndex;
                    if (myListbox != null && myListbox.DeleteSelection != null)
                    {
                        // foreach selected item?
                        myListbox.DeleteSelection((listbox.SelectedItem as DataRowView).Row);
                    }
                    DataRow row = (listbox.SelectedItem as DataRowView).Row;
                    // track this back the real row.
                    if (table_view)
                    {
                        DataRow real_row = row.GetParentRow((row.Table as CurrentObjectTableView).ChildRelationName);
                        real_row.Delete();
                    }
                    else
                    {
                        row.Delete();
                    }

                    if (here >= listbox.Items.Count)
                    {
                        if (here > 0)
                        {
                            listbox.SelectedIndex = here - 1;
                        }
                        else
                        {
                            ;
                        }
                    }
                    else
                    {
                        // probably this is a NO change, so we don't get a selected item changed even
                        // though the item selected is different.
                        listbox.SelectedIndex = here;

                        DataRow tmp_row = (listbox.SelectedItem as DataRowView).Row;
                        if (myListbox != null && myListbox.GetCurrentRow != null)
                        {
                            tmp_row = myListbox.GetCurrentRow(tmp_row);
                        }
                        if (myListbox != null && myListbox.SetCurrent != null)
                        {
                            myListbox.SetCurrent(tmp_row);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Editing is not enabled.");
            }
        }
Exemple #4
0
 /// <summary>
 /// Adds selected item to a list.  Set target_list to the list to put the relation in.  That will provide the parent to relate under
 /// </summary>
 /// <returns></returns>
 public DataRow AddSelected()
 {
     return(MyListBox.AddSelected(this));
 }
Exemple #5
0
 public void RemoveSelected()
 {
     MyListBox.RemoveSelected(this);
 }