White squares in listbox - c#

I have a binded ListBox that displays text. This text is coming from another multiline TextBox. Multiple lines are shown as first line□□second line in ListBox.
I want this text to be displayed as first line second line OR as first line in a ListBox row.
EDIT:
I am actually trying to create a note taking application. The 'ListBox' will show a part of text and 'TextBox' will show the detailed text.

If you check the string, returned via TextBoxt.Text with Multiline set to true, you will notice, that each line ends with "\r\n" sequence. So, depending on what you want, you can split the string from the TextBox using "\r\n" as the parameter in Split method and show these lines as different items in ListBox or replace the "\r\n" in the string with whitespace and show it as a single ListBox item.

Related

How To Get Multiline Text Box to Render Environment.NewLine Correctly?

I am unable to get a multiline text box to render strings separated by Environment.NewLine as strings on multiple lines.
I am querying a database and receiving back a string that is pipe delimited text (for example 123|456|789).
I want to parse that text and put it into a multi-line text box on a Windows Form application. I am parsing the text and doing a replace | with Environment.NewLine. In the text box the string is rendered on one line this way: 123456789. However, when you copy/paste the text out of the box it is correctly parsed (it will have 123 on line 1, 456 on line 2, 789 on line 3).
I want the text to render in the text box with line breaks.
I have tried parsing the string in different ways (using a StringBuilder). I have tried explicitly setting the textbox to multiline = true.
I am parsing the string this way (where orabddr is my Data Reader from the database):
txtTracking.Text = oradbdr.GetString(11).Replace("|", Environment.NewLine);
I want my multiline text box to reflect where the Environment.NewLine characters are.
Double check your string is actually delimited how you've been told.

C# wrap text inside a listbox

I want to display a list of words in a listbox, wrapped them together. Below is an example what I want to do. I was able to add words to listbox with a comma and in one line. Can you please help me to wrap this text.
For comma separation I used,
ListBox.Items.Add(string.Join(",", myList));
Expected output-
Below is my output
I do not think its possible to print multiple text lines per ListBox item with the standard ListBox. Try using a TextBox instead, with Multiline = true
this.textBox1.Text = string.Join(",", UniqueWord(myList));

C# Listbox selected item text

I am working on a wpf app, c#, in visual studio. My aim is to take the selected item text from a listbox on button press and add it to a list whilst also appending it to a text block. My code thus far:
bill.BillItems.Add(lstbxVeg.SelectedItem.ToString());
txtblkBill.Text = String.Join(Environment.NewLine, bill.BillItems);
Where bill is the class name, BillItems the List name. I can see that items are indeed added to the text block, yet instead of the desired string relating to the listbox item selected, it reads System.Data.DataRowView. Where am I going wrong?
EDIT: This is not the correct answer.
lstbxVeg.SelectedItem.Text.ToString()
I think the actual problem is this line:
txtblkBill.Text = String.Join(Environment.NewLine, bill.BillItems);
You mentioned you want to append the value, this line is not accomplishing that.
I think you want to do this:
txtblkBill.Text += lstbxVeg.SelectedItem.ToString();
If that isn't the answer you should look up String.Join() as it takes a String[] not a List.

Combo box not showing items when it has focus

I have 2 combo boxes on a winform, both dragged onto the surface via the designer, both get their items from a database both connect to the dbase fine and are populated properly. But one of them, when it has focus, the selected item is not visible; all that can be seen is the blue background highlight. I have compared the properties of both and cannot discern any setting that is different and that might cause this. When the combobox loses focus the selected item is show, black foreground on a white background as would be expected.
Have a look at the data that is in the Display Member. This might end with blanks/white spaces.
I had this same issue when the combobox was populated using a dataset from an SQL Database.
After changeing the select statement to remove leading and trailing spaces it worked as expected.
The explanation for me:
When editing/having focus, the combobox shows the text right-alligned in reverse video. If the text ends with a lot of blanks, as happens if you have SQL database with fixed length fields that are padded with spaces at the end, the result is that it shows the spaces at the end of the value (right alligned). If you remove the spaces in the select-query (in MSSQL this is done by ltrim(rtrim()) as the text of the selected item is not padded with spaces on the end, therefore it shows the text (in reverse video) until the focus is lost.

Get current line's text (where the caret is blinking) of richtextbox

I really need to get the contents of the line where the caret is blinking in a rich text box control. Suppose I have the following text in a rich text box:
This
is
a
test
I would like to retrieve the text of line 2 by providing its index (for example 2 or 1 if the function is zero-based).
Thanks in advance,
Vali
I'm not sure if the question's title and what you really want to know are the same... If you want to get a line given its index, check the Lines property of the RichTextBox.
http://msdn.microsoft.com/en-us/library/system.windows.forms.textboxbase.lines.aspx
Make sure you have the WordWrap for the text box set to false to make sure the index of the line corresponds to the line where the caret is.
Try this:
var pos = richTextBox1.GetLineFromCharIndex(this.richTextBox1.SelectionStart);
MessageBox.Show(richTextBox1.Lines[pos]);
you can do it
richTextBox1.Lines[1]

Categories