Beispiel #1
0
        public DataRow InsertSelected()
        {
            CurrentObjectDataView  codv = null;
            CurrentObjectTableView cotv = ControlList.schedule.Tables[_target_list] as CurrentObjectTableView;

            if (_target_list != null)
            {
                if (cotv == null)
                {
                    codv = DataSource as CurrentObjectDataView;
                    if (codv == null)
                    {
                        ListBox target_list = this.Parent.Controls[_target_list] as ListBox;
                        if (target_list != null)
                        {
                            cotv = target_list.DataSource as CurrentObjectTableView;
                            if (cotv == null)
                            {
                                codv = target_list.DataSource as CurrentObjectDataView;
                            }
                        }
                    }
                }
                if (cotv != null || codv != null)
                {
                    if (this.SelectedItem != null)
                    {
                        DataRowView drv = this.SelectedItem as DataRowView;
                        if (cotv != null)
                        {
                            return(cotv.InsertChildMember(drv.Row, cotv.Current));
                        }
                        else
                        {
                            return(codv.InsertChildMember(drv.Row, codv.Current));
                        }
                    }
                }
            }
            else if (AddCurrent != null)
            {
                if (this.SelectedItem != null)
                {
                    if (allow_edit)
                    {
                        DataRowView drv = this.SelectedItem as DataRowView;
                        if (cotv != null)
                        {
                            cotv.AddChildMember(drv.Row);
                        }
                        else
                        {
                            codv.AddChildMember(drv.Row);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Editing is not enabled.");
                    }
                }
            }
            return(null);
        }
Beispiel #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);
        }