listbox

c# - Replace Text in ListBox

我们两清 提交于 2019-12-10 12:25:55
问题 How would I say, detect specific text in a listbox and replace it with specific text. Eg: private void timer1_Tick(object sender, EventArgs e) { if(listBox1.Text.Contains("Hi")) { // replace with Hello } } 回答1: In WinForms , you could do it like this: if(listBox1.Items.Cast<string>().Contains("Hi")){ //check if the Items has "Hi" string, case each item to string int a = listBox1.Items.IndexOf("Hi"); //get the index of "Hi" listBox1.Items.RemoveAt(a); //remove the element listBox1.Items.Insert

Sort ListBox numerically in C#

和自甴很熟 提交于 2019-12-10 11:59:50
问题 Im trying to sort a listbox full of numbers numerically. Why doesnt this work? { ArrayList Sorting = new ArrayList(); Sorting.Add (lbNumbers.Text); int[] items = new int[Sorting.Count]; Sorting.CopyTo(items); Array.Sort(items); lbNumbers.Items.Add(items); } 回答1: ArrayList Sorting = new ArrayList(); foreach (var o in listBox1.Items) { Sorting.Add(o); } Sorting.Sort(); listBox1.Items.Clear(); foreach (var o in Sorting) { listBox1.Items.Add(o); } ADDED: For sort in descending order, 1.Create a

c++ winapi impossible to create 2 controls

北城以北 提交于 2019-12-10 11:59:12
问题 I'm trying to create window that contain richedit control and listbox control, the problem is that the second control which I create, doesn't show up. I mean: case WM_CREATE: // In main window procedure { /* Center the main window */ This->CenterWindow(hwnd); /* Initialize the clients list */ This->InitListClients(hwnd); /* Initialize the server log */ This->InitEditLog(hwnd); return 0; } If InitListClients function will be first, only the listbox will show up, if InitEditLog will be first,

what's the meaning of listcount -1

会有一股神秘感。 提交于 2019-12-10 11:49:20
问题 I've been searching on the internet trying to find what the meaning of listcount -1 is, but i can't seem to find the exact answer. why is there -1 beside the listcount? or .list(.listcount -1,1) what is that mean? edit example of the listcount .additem a.value .list(.listcount -1, 1) = ws.cells(A,B).value this adds the value of ws.cells(A,B) to the listbox1 but i don't understand why/how? or i found a code on the internet http://www.ozgrid.com/VBA/multi-select-listbox.htm i understand that

How can I align strings added as listbox items?

[亡魂溺海] 提交于 2019-12-10 11:38:33
问题 I have a listbox where I want to display a list of names and highscores from a character class. I use ListBox.Items.Add to add the following string for each character: public String stringHighscore() { return name + "\t\t\t" + score.ToString(); } The problem is that when the name exceeds a certain length, the score gets pushed to the right. The listbox looks like this (sorry, my rep doesn't allow me to post images yet): (Link to the listbox image on tinypic) I have thought this may be due to

How to check if an item is already in a ListBox

为君一笑 提交于 2019-12-10 11:30:28
问题 Say I have a view model defined this way public class DataVM { public int number { get; set; } public string name { get; set; } } Then somewhere in my code I want to do this to populate DataListbox : List<DataVM> data = new List<DataVM>(); for (int i = 0; i < data.Count; i++) { if (DataListbox.Items.Contains(data[i])) { //do nothing } else { DataListbox.Add(data[i]); } } However, this line if (DataListbox.Items.Contains(data[i])) always evaluate to false even when that item is already in

Silverlight Listbox design- change backgroundcolor of alternate row

不打扰是莪最后的温柔 提交于 2019-12-10 11:02:33
问题 how to change listbox to set background color of alternate row diff... e.g. Listbox having 6 rows 1st,3rd,5th row having "blue" background and 2nd, 4th, 6th row having "white" background. 回答1: Here is one way to do it: http://forums.silverlight.net/forums/t/14345.aspx 来源: https://stackoverflow.com/questions/3183459/silverlight-listbox-design-change-backgroundcolor-of-alternate-row

VBA realtime filter Listbox through Textbox

大兔子大兔子 提交于 2019-12-10 10:19:44
问题 I would like to filter a Listbox created from a list of values stored in a worksheet depending on text written in a textbox contained in the same userform. My Listbox has 4 or 5 columns (depending on OptionField selection) and I would like to search all the columns for the text written. Example: I write "aaa" in TextField and the Listbox should return a list based on all the lines whose column 1 or 2 or 3 or 4 or 5 contain "aaa". Below my code to refresh the list on OptionField selection

How to bind a ListBox to a DataTable from a session object?

末鹿安然 提交于 2019-12-10 10:08:53
问题 I have a session object that contains a DataTable from my previous page, and i would like to bind this DataTable to a ListBox. I'v done this: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["bestStocks"] !=null) { DataTable dt = new DataTable(); dt = (DataTable)Session["bestStocks"]; DataView dv = new DataView(dt); BestStockslb.DataSource = dt; BestStockslb.DataBind(); } } } I get this result: Any suggestion? thanks, liron 回答1: It seems you have forgot

Windows Phone: how to disable touch scrolling in ScrollViewer (Listbox)?

南笙酒味 提交于 2019-12-10 09:45:39
问题 i have a scrollviewer with a listbox inside: i need to disable the vertical scroll by touch, how can i? In other words, the user can't scroll with the touch (i have put buttons, but this is another story). <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled" x:Name="imagesScrollview" Width="480" Height="595" Margin="0,112,0,63"> <ScrollViewer.RenderTransform> <CompositeTransform/> </ScrollViewer.RenderTransform> <ListBox Name="listavideo" Height="595"