listbox

How to populate listbox dynamically with SQL values

…衆ロ難τιáo~ 提交于 2019-12-05 15:17:40
I am a C# beginner. What I am trying to do is pull data from a column in a SQL database and write it to a listbox. Basically, I want the data in the part_num column of my table to be displayed dynamically in the listbox. I have seen: this.listParts.Items.AddRange(new object[] {"Part1", "Part2"}); But how would I go about replacing “Part1” and “Part2” with dynamically generated values from SQL? public mainForm() { InitializeComponent(); SqlConnection conn = new SqlConnection( "Data Source=DBELL;Initial Catalog=part_table;Integrated Security=True"); conn.Open(); DataSet ds = new DataSet();

Change how items are displayed WPF list box

放肆的年华 提交于 2019-12-05 15:04:47
I have a WPF window which displays a ListBox . I've changed the ListBox 's item template so that the list box displays rectangular items which can be selected. Now I'd like to modify the ListBox 's ItemsPanelTemplate so that the items are displayed in a grid instead of either a vertical or horizontal list. Specifically I'd like the first item to go in the top right corner of the ListBox and then second item below it and third under that until the height of the next item would make the column of items taller than the height of the ListBox itself. At that point it should start a second column

ListBox ItemContainerGenerator returns null even when listbox has items

你。 提交于 2019-12-05 14:18:57
I've a listbox with couple of items, till the time no scrollbar appears everything goes perfectly fine but once scrollbar comes then ItemContainerGenerator returns null. I read some blogs and found it may be because of vertualization stackpanel. If i disable that then it may work but in my case it would make listbox too much heavy and less efficient. Here is the code for listbox: <ListBox x:Name="EventListBox" DockPanel.Dock="Top" Margin="5,5,5,5" FocusVisualStyle="{x:Null}" ItemsSource="{Binding EventModelViewCollectionView}" Style="{StaticResource DefaultListBoxStyle}" ItemTemplate="

WPF Listbox binding

与世无争的帅哥 提交于 2019-12-05 14:15:58
I have a physician object, and one of its properties is an ObservableList of clinics. It is being used in a window to show the details of a physician. I can get individual properties to bind to TextBox and ComboBox controls, but I can't get the list of clinics to bind to my ListBox . Here is the xaml for my ListBox : <ListBox Height="318" HorizontalAlignment="Left" Margin="422,0,0,0" Name="lbClinic" VerticalAlignment="Top" Width="158" SelectedValue="{Binding ClinicID, Path=Clinics, Mode=TwoWay, UpdateSourceTrigger = PropertyChanged}" SelectedValuePath="ClinicID" DisplayMemberPath="Name"

how to add tooltips on winform list box items

房东的猫 提交于 2019-12-05 14:13:58
I am using win form's list box control. I want to add tool tips on list items. I could not find any default such properties. Please share me , how can i add tool tips on winform list box items ? Thank You If you want to do it in a listbox you will need to do it manually. Add a tooltip to the form and update the tooltip based on the mouses postion. An easier way to do this might be to use a DataGridView control like this: DataGridView1.RowHeadersVisible = False DataGridView1.ColumnHeadersVisible = False DataGridView1.Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader

How do I make a header for a ListBoxItem?

ぃ、小莉子 提交于 2019-12-05 13:10:21
问题 I use ListBox in my application. ListBox has two columns. I want to make a title for the columns. It is layout <Window.Resources> <Style x:Key="borderBase" TargetType="Border"> <Setter Property="BorderBrush" Value="Black" /> <Setter Property="BorderThickness" Value="1" /> </Style> </Window.Resources> <Grid> <Grid.RowDefinitions> <RowDefinition Height="1*" /> <RowDefinition Height="7*" /> </Grid.RowDefinitions> <!-- Title --> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition />

Add image to listbox

扶醉桌前 提交于 2019-12-05 12:19:23
I have a few images with some text, I need to show the image with the relevant text in a listbox. Browsing google I came across this sample class, public class Customer { public string Fname; public string Lname; public Customer(string firstName, string lastName) { Fname = firstName; Lname = lastName; } public override string ToString() { return Fname + " " + Lname; } } lstCustomers.Items.Add(new Customer("Foo","Bar")); The above code works fine as it only returns string, how do I return an image and a string together so that it gets added to the listbox? Best Regards @nand Just use a

WPF ListBox SelectionChanged event

[亡魂溺海] 提交于 2019-12-05 11:24:10
I have a problem with listbox. When in my program I click on one ListBoxItem, I want to change/open the window and preorder it before. But the problem is that it firstly fires the event and then it changes selection. Code: private void LB_Playlist_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (LB_Playlist.SelectedItem != null) { try { List<string> _tempList = new List<string>(); File_Load_List(LB_Playlist.SelectedItem.ToString(), _tempList); LoadListIntoBox(_tempList); G_SongList.Visibility = Visibility.Visible; AnimationMove(G_Playlist, G_Playlist.Margin, new Thickness(

Listview inside of scrollviewer prevents scrollviewer scroll

徘徊边缘 提交于 2019-12-05 10:03:27
问题 I have a scrollviewer with a couple listboxes in it. The problem is if a user uses the middle mouse roller to scroll the scrollviewer while their mouse is over a listview. The listview scrolls its internal scrollviewer to the bottom and then continues to capture the mouse, preventing the containing scrollviewer from scrolling. Any ideas on how to handle this? 回答1: That happens because the ListView 's ( ListBox 's, actually) content template wraps its items with a ScrollViewer by itself. The

How to make a loading graphic in WPF XAML?

限于喜欢 提交于 2019-12-05 08:23:45
So I have a little WPF XAML that gets the titles of my RSS feed and puts them in a ListBox. However, it takes about 2 seconds to load. How can I have put some kind of AJAXy spinning graphic in the ListBox until the data is there? Here is the code: <Window x:Class="WpfApplication5.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <StackPanel> <StackPanel.Resources> <XmlDataProvider x:Key="ExternalColors" Source="http://www.tanguay.info/web/rss" XPath="/"/> </StackPanel