private void UpdateHighlightedItem(ListBoxItem newItem)
        {
            if (HighlightedItem == newItem)
                return;

            // Unselect old value.
            if (HighlightedItem != null)
                HighlightedItem.IsSelected = false;

            HighlightedItem = newItem;

            // Select new value.
            if (HighlightedItem != null)
            {
                HighlightedItem.IsSelected = true;
                HighlightedItem.BringIntoView();
            }
        }
예제 #2
0
        /// <summary>
        /// First determine whether the drag data is supported.
        /// Second determine what type the container is.
        /// Third determine what operation to do (only copy is supported).
        /// And finally handle the actual drop when <code>bDrop</code> is true.
        /// </summary>
        /// <param name="bDrop">True to perform an actual drop, otherwise just return e.Effects</param>
        /// <param name="sender">DragDrop event <code>sender</code></param>
        /// <param name="e">DragDrop event arguments</param>
        private void DragOverOrDrop(bool bDrop, object sender, DragEventArgs e)
        {
            string[] files = this.GetData(e) as string[];
            if(files != null) {
                e.Effects = DragDropEffects.None;
                ItemsControl dstItemsControl = sender as ItemsControl;  // 'sender' is used when dropped in an empty area
                if(dstItemsControl != null) {
                    foreach(string file in files) {
                        if(sender is TabControl) {
                            if(bDrop) {
                                TabItem item = new TabItem();
                                item.Header = System.IO.Path.GetFileName(file);
                                item.ToolTip = file;
                                dstItemsControl.Items.Insert(0, item);
                                item.IsSelected = true;
                            }
                            e.Effects = DragDropEffects.Copy;
                        }
                        else if(sender is ListBox) {
                            if(bDrop) {
                                ListBoxItem dstItem = Utilities.FindParentControlIncludingMe<ListBoxItem>(e.Source as DependencyObject);
                                ListBoxItem item = new ListBoxItem();
                                item.Content = System.IO.Path.GetFileName(file);
                                item.ToolTip = file;
                                if(dstItem == null)
                                    dstItemsControl.Items.Add(item);    // ... if dropped on an empty area
                                else
                                    dstItemsControl.Items.Insert(dstItemsControl.Items.IndexOf(dstItem), item);

                                item.IsSelected = true;
                                item.BringIntoView();
                            }
                            e.Effects = DragDropEffects.Copy;
                        }
                        else if(sender is TreeView) {
                            if(bDrop) {
                                if(e.Source is ItemsControl)
                                    dstItemsControl = e.Source as ItemsControl; // Dropped on a TreeViewItem
                                TreeViewItem item = new TreeViewItem();
                                item.Header = System.IO.Path.GetFileName(file);
                                item.ToolTip = file;
                                dstItemsControl.Items.Add(item);
                                item.IsSelected = true;
                                item.BringIntoView();
                            }
                            e.Effects = DragDropEffects.Copy;
                        }
                        else {
                            throw new NotSupportedException("The item type is not implemented");
                        }
                        // No need to loop through multiple
                        // files if we're not dropping them
                        if(!bDrop)
                            break;
                    }
                }
                e.Handled = true;
            }
        }
예제 #3
0
		public String CreateNewPerson (ListBox PersonenListBox)
			{
			String PersonenIDToCreate = System.Guid.NewGuid ().ToString ();
			String InsertCommand = "INSERT INTO [Personen] ([ID], [Name], [Bereich]) VALUES " +
								"('" + PersonenIDToCreate + "', 'N Bitte Werte eintragen', '" + m_Bereich + "')";
			DataBase.RunSQLBatch (InsertCommand);
			String SelectStatement = "Select * from PersonenFull where ID = '" + PersonenIDToCreate
				+ "' and Bereich = '" + m_Bereich + "'";
			DataSet NewPersonenDataSet = DataBase.GetCommonDataSet (SelectStatement);
			if (NewPersonenDataSet.Tables ["PersonenFull"].Rows.Count < 1)
				return "";
			DataRow NewFullPerson = NewPersonenDataSet.Tables ["PersonenFull"].Rows [0];
			ListBoxItem NewEntry = new ListBoxItem ();
			NewEntry.Tag = PersonenIDToCreate;
			NewEntry.Content = GetPersonenStringFromFullRow (NewFullPerson);
			PersonenListBox.Items.Add (NewEntry);
			NewEntry.BringIntoView ();
			PersonenListBox.SelectedItem = NewEntry;
			return PersonenIDToCreate;
			}