listbox

Loading a listbox from a file

纵然是瞬间 提交于 2020-01-14 03:19:51
问题 This is my first time creating a C# program so I apologize if this question seems basic. I have 3 list boxes on my design form along with 3 buttons I'd like to load a list of item into each text box when I click the corresponding button for the listbox. can someone instruct me on how to do this. 回答1: Abbas has given you a sufficient answer, but there are a couple of problems with it, so I thought I would add my own response. The issues: Streams (anything that implements IDisposable ) need to

WinForms localization. How to change the language of a Menu

走远了吗. 提交于 2020-01-13 19:28:24
问题 EDIT: Although useful, the "duplicate" question does not give an answer to this question. First, the main theme here is Menus , so please don't mark this question duplicate to a question that is not. I have been trying to understand correctly how to localize an application. Right now I have a form with a label, a menu and a listbox. I have localized the form so that now I have three resx files. I used Z.R.T. answer to implement the listbox to change the language on runtime. Instead of his

Display selected listbox items' data in wpf

北战南征 提交于 2020-01-13 09:38:09
问题 I'm in search of some help. I've created a very basic MVVM setup. My object is called VNode which has the properties Name,Age,Kids. What I want to happen is when the user selects VNodes on the left, it displays their more in depth data on the right as scene in the image below. I'm not sure how to go about doing this. image 1: Current Image 2: Goal If you don't feel like using the code below to recreate the window you can grab the project solution files from here: DropboxFiles VNode.cs

ListBox Grouping issue

戏子无情 提交于 2020-01-13 08:25:17
问题 I am trying to Group my collection which is based on my following model: public class Person { public string FirstName { get; set; } public string LastName { get; set; } public Role PersonRole { get; set; } } public class Role { public int Id { get; set; } public string RoleName { get; set; } } My PersonCollection, public ObservableCollection<Person> PersonList; The collection is populated with three Person object, two with identical roles. I want to group all my persons as per their RoleName

Win32 LB_GETTEXT returns garbage

混江龙づ霸主 提交于 2020-01-13 02:43:07
问题 I have a problem which is most likely a simple problem, but neverthe less still a problem for me. I am using the Listbox in Win32 / C++ and when getting the selected text from my listbox the string returned is just garbage. It is a handle to a struct or similar? Below is the code and an example of what I get. std::string Listbox::GetSelected() { int index = -1; int count = 0; count = SendMessage(control, LB_GETSELCOUNT, 0, 0); if(count > 0) { index = SendMessage(control, LB_GETSEL, 0, 0); }

Win32 LB_GETTEXT returns garbage

笑着哭i 提交于 2020-01-13 02:43:06
问题 I have a problem which is most likely a simple problem, but neverthe less still a problem for me. I am using the Listbox in Win32 / C++ and when getting the selected text from my listbox the string returned is just garbage. It is a handle to a struct or similar? Below is the code and an example of what I get. std::string Listbox::GetSelected() { int index = -1; int count = 0; count = SendMessage(control, LB_GETSELCOUNT, 0, 0); if(count > 0) { index = SendMessage(control, LB_GETSEL, 0, 0); }

Bind listbox in WPF with grouping

冷暖自知 提交于 2020-01-12 10:14:51
问题 I've got a collection of ViewModels and want to bind a ListBox to them. Doing some investigation I found this. So my ViewModel look like this (Pseudo Code) interface IItemViewModel { string DisplayName { get; } } class AViewModel : IItemViewModel { string DisplayName { return "foo"; } } class BViewModel : IItemViewModel { string DisplayName { return "foo"; } } class ParentViewModel { IEnumerable<IItemViewModel> Items { get { return new IItemViewModel[] { new AItemViewModel(), new

WPF: C# How to get selected value of Listbox?

时光毁灭记忆、已成空白 提交于 2020-01-11 14:31:50
问题 I am trying to fetch the selected value of the listbox. When I actually try LstGroup1.SelectedItem I get the value { BoothID = "4", BoothName = "HP" } and even if i try to get the value from LstGroup1.SelectedValue the output is same. Now I want to fetch BoothID i.e. the expected output is 4 but i am unable to get so. My ListBox name is LstGroup1 . public List<object> BoothsInGroup1 { get; set; } // Inside the Constructor BoothsInGroup1 = new List<object>(); //After Fetching the value add

WinForms ListBox with readonly/disabled items

橙三吉。 提交于 2020-01-11 09:12:08
问题 Is there a way to make some of the items in a ListBox readonly/disabled so they can't be selected? Or are there any similar controls to ListBox to provide this functionality? 回答1: ListBox doesn't have support for that. You can bolt something on, you could deselect a selected item. Here's a silly example that prevents even-numbered items from being selected: private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { for (int ix = listBox1.SelectedIndices.Count - 1; ix >= 0; ix--)

Cannot do key-value in listbox in C#

若如初见. 提交于 2020-01-11 05:02:06
问题 i'm writing a C# app using winforms. I have a listbox. I get my data from xml file, user name and their id's. I want names to be shown in the listbox and when I select one of them, I want to get his/her id using selectedValue property. However I cannot do this. I tried keyValuePair which shows "[username, id]" in the listbox which is not good (see code below). How can I simulate html select in c# in short? I want names to be shown in the listbox but want to get id's in the backend. Thanks...