Пример #1
0
        void DoClick()
        {
            if (!allow_edit)
            {
                MessageBox.Show("Edit is not enabled.");
                return;
            }
            ListBox list  = null;
            Control c     = Parent.Controls[_target_list];
            int     index = -1;

            if (c != null)
            {
                list = c as ListBox;

                if (list != null)
                {
                    CurrentObjectDataView codv = list.DataSource as CurrentObjectDataView;
                    index = list.SelectedIndex;
                    if (codv != null)
                    {
                        IMySQLRelationTableBase relation_table = codv.Table as IMySQLRelationTableBase;
                        if (relation_table != null)
                        {
                            relation_table.MoveRowUp(codv.Current);
                        }
                    }
                    CurrentObjectTableView cotv = list.DataSource as CurrentObjectTableView;
                    if (cotv != null)
                    {
                        IMySQLRelationTableBase relation_table = cotv.relation_data_table as IMySQLRelationTableBase;
                        if (relation_table != null)
                        {
                            relation_table.MoveRowUp(cotv.Current);
                        }
                    }
                }
            }
            if (list != null && list.SelectedItem != null)
            {
                if (index > 0)
                {
                    list.SelectedIndex = index;
                    list.SelectedIndex = index - 1;
                }
            }
        }
Пример #2
0
        void DoClick()
        {
            if (!allow_edit)
            {
                MessageBox.Show("Edit is not enabled.");
                return;
            }
            int     index = -1;
            ListBox list  = null;

            foreach (Control c in Parent.Controls)
            {
                list = c as ListBox;
                if (c.GetType() == typeof(thing))
                {
                    if (list != null)
                    {
                        index = list.SelectedIndex;
                    }
                    do_movedown((list.SelectedItem as DataRowView).Row);
                    break;
                }

                if (list != null)
                {
                    if (list.DataSource.GetType() == typeof(thing))
                    {
                        index = list.SelectedIndex;
                        CurrentObjectDataView codv = list.DataSource as CurrentObjectDataView;
                        do_movedown(codv.Current);
                        break;
                    }
                }
                list = null;                 // make sure we don't get a false handling if the last thing happened to be a listbox
            }
            if (list != null)
            {
                if (index < (list.Items.Count - 1))
                {
                    list.SelectedIndex = index + 1;
                }
            }
        }
Пример #3
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);
        }
Пример #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 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);
        }