c# - How can i make that if an item in a listBox is out of the bound on the right so it will move one line down? -



c# - How can i make that if an item in a listBox is out of the bound on the right so it will move one line down? -

i have code in new form add together text textbox , it's added listbox item:

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; namespace gatherlinks { public partial class changelink : form { public changelink() { initializecomponent(); } public string gettext() { homecoming textbox1.text; } private void button1_click(object sender, eventargs e) { if (!string.isnullorempty(textbox1.text)) { dialogresult = dialogresult.ok; } else { } } private void changelink_load(object sender, eventargs e) { this.acceptbutton = button1; } } }

and how add together text listbox:

private void button2_click(object sender, eventargs e) { cl = new changelink(); cl.startposition = formstartposition.centerparent; dialogresult dr = cl.showdialog(this); if (dr == dialogresult.cancel) { cl.close(); } else if (dr == dialogresult.ok) { label4.text = cl.gettext(); mainurl = cl.gettext(); if (!localykeywords.containskey(mainurl)) { newurl = true; keysvaluesupdate(); } else { newurl = false; keysvaluesupdate(); } optionsdb.set_changewebsite(cl.gettext()); cl.close(); listbox1.selectedindex = listbox1.items.count - 1; } }

the problem if text long in right bound/border of listbox text of item cut. see want somehow move 1 line downwards or how much lines need show rest of item text/name

so count 1 item if needed on lines.

update:

this part load items listbox when im running application:

private void listboxloadkeys(dictionary<string, list<string>> dictionary, string filename) { int t = listbox1.width; using (streamreader sr = new streamreader(filename)) { while ((line = sr.readline()) != null) { int = line.count(); tokens = line.split(','); dictionary.add(tokens[0], tokens.skip(1).tolist()); string tt = tokens[1].substring(t - tokens[1].length); data.add("url: " + tokens[0] + " --- " + "localy keyword: " + tokens[1]); } } listbox1.datasource = data; }

so variable t listbox length(width) , in line tried calculate , text of tokens[1]"

string tt = tokens[1].substring(t - tokens[1].length);

but im getting error startindex cannot larger length of string

now know listbox length(width) don't want set text tokens[1] in new line if it's out of bound out of listbox width(length)

how can prepare , ?

updated again:

changed code 1 time again im trying first check if each line in variable info lngth bigger variable t:

private void listboxloadkeys(dictionary<string, list<string>> dictionary, string filename) { int t = listbox1.width; using (streamreader sr = new streamreader(filename)) { while ((line = sr.readline()) != null) { int = line.count(); tokens = line.split(','); dictionary.add(tokens[0], tokens.skip(1).tolist()); //string tt = tokens[1].substring(t - tokens[1].length); data.add("url: " + tokens[0] + " --- " + "localy keyword: " + tokens[1]); if (data[i].length > t) { messagebox.show("big"); } } } listbox1.datasource = data; } if (data[i].length > t) { messagebox.show("big"); }

but im getting error: index out of range. must non-negative , less size of collection

you can't standard listbox. need create own multi line listbox. see link guidance. http://www.codeproject.com/articles/2695/an-editable-multi-line-listbox-for-net

i've implemented @ work (ignoring author's poor selection of colour scheme), , works fine.

c#

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -