private void ResultsListBox_MouseDown(object sender, MouseEventArgs e) { if (ResultsListBox.SelectedItems.Count == 0) { return; } var dataObject = new DataObject(); var filePaths = new StringCollection(); foreach (var item in ResultsListBox.SelectedItems) { filePaths.Add(Path.GetFullPath(item.ToString())); } dataObject.SetFileDropList(filePaths); ResultsListBox.DoDragDrop(dataObject, DragDropEffects.All); }
private void Search() { ResultsListBox.Items.Clear(); if (GetMovies()?.Length > 0) { foreach (Movie movie in GetMovies()) { ResultsListBox.Items.Add(movie.Title); } } ReloadGrammars(); if (!ResultsListBox.Items.IsEmpty) { ResultsListBox.Focus(); } }
// ReSharper restore UnusedAutoPropertyAccessor.Local private void FindButton_Click(object sender, EventArgs e) { #if NO_ACTIVE_DIRECTORY MessageBox.Show("Active Directory Search Disabled.", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information); #else var context = new PrincipalContext(ContextType.Domain, "nps", "OU=AKR,DC=nps,DC=doi,DC=net"); string search = EditorTextBox.Text + "*"; var principal = new UserPrincipal(context) { Surname = search, Enabled = true }; var searcher = new PrincipalSearcher { QueryFilter = principal }; var query = from Principal p in searcher.FindAll() orderby p.DisplayName select new EditorListItem { DisplayName = p.Name + " (" + p.Description + ") - NPS\\" + p.SamAccountName, DomainName = "NPS\\" + p.SamAccountName, }; ResultsListBox.DisplayMember = "DisplayName"; var data = query.ToList(); ResultsListBox.DataSource = data; EnableControls(); //If the Datasource is empty, then SelectedIndexChanged is not called. if (data.Count > 0) { ResultsListBox.Focus(); } else { MessageBox.Show("Nobody found with that name.", "Try again", MessageBoxButtons.OK, MessageBoxIcon.Information); EditorTextBox.Focus(); } #endif }
private static void SetImageData(BitmapImage bmp, string imageUrl, object userData) { BatchApplyFolderBox _box = userData as BatchApplyFolderBox; if (_box != null) { // just to be sure... _box.TheImage.Source = bmp; // clone the watermark from the Owner window... just for the sake of display consistency ;) ResultsListBox _form = _box.Owner as ResultsListBox; if (_form != null) { try { RenderTargetBitmap _bmp = new RenderTargetBitmap((int)_form.newImage.Width, (int)_form.newImage.Height, 96, 96, PixelFormats.Pbgra32); _bmp.Render(_form.NewImageCanvas); _box.TheImage.Source = _bmp; } catch { } } } }
private void NavigateListBox(Key key) { int numberOfItems = ResultsListBox.Items.Count; if (numberOfItems <= 1) { return; } int index = ResultsListBox.SelectedIndex; int scrollOffset; int pageHeight; // The vertical offsets and extent in the ScrollViewer is measured in 'items'. var scrollViewer = ResultsListBox.GetVisualDescendants() .OfType <ScrollViewer>() .FirstOrDefault(); if (scrollViewer != null) { // ScrollViewer.VerticalOffset is the index of the first visible item. scrollOffset = (int)scrollViewer.VerticalOffset; // ScrollViewer.ViewportHeight is number of visible items (rounded down). pageHeight = Math.Max(1, (int)scrollViewer.ViewportHeight); } else { scrollOffset = 0; pageHeight = 1; } if (key == Key.Down) { // Move down. index = Cycle(++index, numberOfItems); } else if (key == Key.Up) { // Move up. index = Cycle(--index, numberOfItems); } else if (key == Key.PageUp) { if (index == -1) { // No item selected: Select first item. index = 0; } else if (index == 0) { // First item selected: Jump to last item. index = numberOfItems - 1; } else if (index == scrollOffset) { // First visible item selected: Jump up by one page. index = Clamp(index - pageHeight, numberOfItems); } else { // Jump to first visible item. index = scrollOffset; } } else if (key == Key.PageDown) { if (index == -1) { // No item selected: Select first item. index = 0; } else if (index == numberOfItems - 1) { // Last item selected: Jump to first item. index = 0; } else if (index == scrollOffset + pageHeight - 1) { // Last visible item selected: Jump down by one page. index = Clamp(index + pageHeight - 1, numberOfItems); } else { // Jump to end of page. index = Clamp(scrollOffset + pageHeight - 1, numberOfItems); } } if (index != -1) { Debug.Assert(0 <= index && index < numberOfItems, "Invalid index."); ResultsListBox.SelectedIndex = index; // Important: ScrollIntoView() causes an exception if virtualization is enabled and the // layout (e.g. width) of the ListBox changes. // --> Use a fixed-size popup to ensure that the layout does not change while scrolling! ResultsListBox.ScrollIntoView(ResultsListBox.Items[index]); } }