New line "\n" does not work yet no errors are given - c++-cli

I have a program that loads a checked list box, then the user selects the items they want and selects a button to say they are done. The checked items are read in a contiguous string with a newline "\n" at the end of each string added. My problem is everything works ok except the newline "\n", and I don't know why.
Code
private: System::Void bntSelected_Click(System::Object^ sender, System::EventArgs^ e) {
int numSelected = this->checkedListBox1->CheckedItems->Count;
if (numSelected != 0)
{
// Set input focus to the list box.
//SetFocus(lstReceiver);
String^ listBoxStr = "";
// If so, loop through all checked items and print results.
for (int x = 0; x < numSelected; x++)
{
listBoxStr = listBoxStr + (x + 1).ToString() + " = " + this->checkedListBox1->CheckedItems[x]->ToString() + "\n";
}
lstReceiver->Items->Add(listBoxStr);
}
}

The string is being formed correctly, but the ListBox control doesn't show newlines in its list items - each item is pushed onto a single line. You can see this by debugging, or by adding a Label to the form with AutoSize set to false - the label will show the newline(s) in the string properly.
Related (C#): How to put a \n(new line) inside a list box?

Instead of ā€˜\nā€™, try ā€˜\r\nā€™. This may be a windows thing.

Related

How can i close window and relaod in asp.net

My code look like below.
protected void btnApprove_Click(object sender, EventArgs e)
{
if (id == "Button2")
{
string sql = #"update AdjTranSeqDetails set Approver1Status = 'Rejected',finalStatus='Rejected' ,updatedtime = GETDATE(),Approver1Comment ='{1}',modifieduser = '{2}' where TranSeq ={0}";
sql = String.Format(sql, tbxTranSeq.Text, TextBox2.Text, Master.CurrentUser);
string sql2 = #"INSERT INTO AdjTranSeqDetailsHistory SELECT * FROM AdjTranSeqDetails WHERE tranSeq={0}";
sql2 = String.Format(sql2, tbxTranSeq.Text);
string sql3 = #"delete from AdjTranSeqDetails where tranSeq={0}";
sql3 = String.Format(sql3, tbxTranSeq.Text);
if (dba.SqlUpdate(sql, ref ex, ref rowCt) || dba.SqlInsert(sql2, ref ex, ref rowCt) ||dba.SqlDelete(sql3, ref ex, ref rowCt))
{
string sscript = "<script language=\"Jscript\" > ";
if (Master.PageMode == "View")
{
sscript += "if (window.opener && !window.opener.closed) ";
sscript += "{window.opener.DoSearch();}";
}
sscript += "window.opener='x';self.close();";
sscript += "</Script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "SelfClose", sscript);
}
}
updateapp();
GetBillTranInfo();
}
Like Button2, like have 10 button. If one if condition function done I need to close the window and need to reload the page. Can I do like this?
I have tried like above but that is not working for me.
In my user controls, after updating data I do:
Response.Redirect(Request.RawUrl);
That ensures that the page is reloaded, and it works fine from a user control. You use RawURL and not Request.Url.AbsoluteUri to preserve any GET parameters that may be included in the request.
You probably don't want to use: __doPostBack, since many aspx pages behave differently when doing a postback.

How to make a ToolStripMenuItem hold a variable value to be recalled later?

I have a form that has a MenuStrip at the top. I only have one ToolStripMenuItem called Dates. I have written code that executes when an "Add" button is clicked which adds a new menu item underneath "Dates". This menu item is named by concatenating some variables which store user input. Here is everything I have for the "Add" button click event. It all works, but I want display the same info that gets displayed in the label when the click event happens to be saved to the submenu item too. So I want to be able to click that sub-menu item that is created and be able to see what input was saved to it when the Add button is clicked.
private: System::Void btnAdd_Click(System::Object^ sender, System::EventArgs^ e)
{
//add the input to the variables
String^ month = txtMonth->Text;
String^ day = txtDay->Text;
String^ year = txtYear->Text;
double tips = Double::Parse(txtTips->Text);
//make sure the date input is correct
if (txtMonth->Text == "" || txtDay->Text == "" || txtYear->Text == "" || Double::Parse(month) < 1 || Double::Parse(month) > 12
|| Double::Parse(day) < 1 || Double::Parse(day) > 31 /*|| Double::Parse(year)!=*/)
{
//show message box
MessageBox::Show("Please enter the date in the correct format.", "Error", MessageBoxButtons::OK,
MessageBoxIcon::Error);
//clear the boxes
txtMonth->Clear();
txtDay->Clear();
txtYear->Clear();
}
else
{
//for the menu bar
String^ date = month + "/" + day + "/" + year;
datesToolStripMenuItem->DropDownItems->Add(date)->Equals(date);
//print to label
lblPrint->Text = month + "/" + day + "/" + year + " - " + tips.ToString("c");
//clear the boxes
txtMonth->Clear();
txtDay->Clear();
txtYear->Clear();
txtTips->Clear();
}
}
FYI. I haven't written any code to do what I want to do. I just have no idea where to start for that, so I've shared what I have before that.

How to write data into excel in a row/column in Sorted Form- ( i am using JXL ), Used Collection.sort(list) but not working

I am Not getting ---
I need to Pick list items in E commerce application search box . and Have to Print each Line By line in a column or any number of rows and column, in Excel in sorted form
i am able to get the name of items in the Search and print them in eclipse console.
what can be the logic to Print them one after other in Excel in sorted form , do i need to save them all in an array first or something else .
Here in this Code I am Getting -- Items From the Search box in the E commerce Application and printing them in the Excel.
Need the logic that any random number of search items gets printed in the Excel in sorted Form
i used the code below to print all the search list items in the Column(Excel) ,what change can be made to print them in sorted order
// picking list items//
List <WebElement> listItems = driver.findElements(By.xpath(".//form[#class='_1WMLwI']//ul/li"));
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
String[] text = new String[10];
arrylngth=listItems.size();
System.out.println("Length of arrylngth" + arrylngth);
for (int col = 0; col < arrylngth; col++)
{ text[col]=listItems.get(col).getText();
System.out.println("Original List "+" "+ text[col]);
// insert data into Excel sheet
for (int row = 0; row <1 ; row++) {
// create an empty array list with an initial capacity
List<String> arrlist = new ArrayList<String>();
// use add() method to add elements in the list
arrlist.add(text[col]);
Collections.sort(arrlist);
System.out.println("sorted Array "+" "+ arrlist);
for(String counter: arrlist){
System.out.println("After Sorting:"+""+ counter);}
Label label1 = new Label(row,col,text[col]);
try {
shSheet.addCell(label1);
} catch (RowsExceededException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
I got the Answer :
Step 1: Need to pick the List Web-Elements -
List <WebElement> listItems = driver.findElements(By.xpath(".//form[#class='_1WMLwI']//ul/li"));
Step 2: Need To Create a String List where i can store the list elements name ( as collection.sort() applied to sting list)
List<String> al = new ArrayList<String>();
Step 3: Apply For Loop to insert data into the String List
for (int i = 0; i <listItems.size(); i++)
{
al.add(listItems.get(i).getText());
System.out.println("Unsorted list " + al);
}
Step 4: Apply Collection.sort() onto the string List , it will Sort the List content
Collections.sort(al);
step 5: Now there is a need to print the sorted list in the Console\
for (String list:al)
{
System.out.println("sorted list"+ " " + al);
}
as we are done with sorted String list , now its an easy task to write the Sorted list into the Excel using JXL or POI using, Write Excel code.

Monogame windows - make a textview scrollable

I am trying to do an appication in monogame windows. I have a long text to be displayed on screen. I tried to render it on screen using spriteBatch.Drawstring, was succesful to an extent. But, the text did not fit into a required area. I had followed this tutorial. I need a vertical scroll to be implemented to have the entire text inside my desired area. Can anyone suggest some help. This is my current code :
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
_boxTexture = new SolidColorTexture(GraphicsDevice, Color.Red);
_borderRectangle = new Rectangle(100, 100, 500, 500);
_textboxRectangle = new Rectangle(105, 105, 490, 490);
_font = Content.Load<SpriteFont>("Rockwell");
_text = "He determined to drop his litigation with the monastry, and relinguish his claims to the wood-cuting and fishery rihgts at once. He was the more ready to do this becuase the rights had becom much less valuable, and he had indeed the vaguest idea where the wood and river in quedtion were.";
}
private String parseText(String text)
{
String line = String.Empty;
String returnString = String.Empty;
String[] wordArray = text.Split(' ');
foreach (String word in wordArray)
{
if (font.MeasureString(line + word).Length() > textBox.Width)
{
returnString = returnString + line + '\n';
line = String.Empty;
}
line = line + word + ' ';
}
return returnString + line;
}
and inside draw function :
spriteBatch.DrawString(font, parseText(text), new Vector2(textBox.X, textBox.Y), Color.White);
You can do it in the draw method instead.
Then just do what you're doing now, but instead of creating a string that you return, you just call
spriteBatch.DrawString(font, line, textPostion, Color.White);
instead. Where textPosition is just equal to the textbox position, to begin with and then you increase the Y position with font.MeasureString(line).Y for each iteration:
textPosition.Y += font.MeasureString(line).Y;
Then you check for
if(font.MeasureString(line).Y + textPosition.Y < textBox.Y + textBox.Height
|| textPosition.Y > textBox.Y)
{
continue;
}
Then just look for input of the keyboard arrows for instance (or create some buttons for scrolling up and down), and increase or decrease the textPosition.Y accordingly. Then you will have vertically scrolling textbox.
You can then make some lock by defining a minimum Y value for the position, such that the text stop when scrolling to the bottom or to the top.

How to setText in a textArea from an ArrayList?

I have an ArrayList ArrayList<String> externalDataList = new ArrayList<>(1600);and I would like to display in a textArea first 3 strings, but I can't succed:
Here is my code
textareaShowPreview.setPrefRowCount(3);
Iterator<String> it = externalDataList.iterator();
int tot = 0;
while(it.hasNext() && tot<3){
String element = it.next();
textareaShowPreview.setText(element + "\n");
System.out.println("elements are: " + element);
tot++;
}
The sout correctly print first 3 strings
element are: 23/05/2007 ,30.9455,31.2545,30.9091,30.9545,7518142
element are: 24/05/2007 ,30.6545,31.0909,30.5364,30.6909,12851606
element are: 25/05/2007 ,30.6636,30.8545,30.4818,30.8091,9392088
but in textArea I have only first one
How do I have to modify my code to show in textArea all three strings, one string per row?
Use appendText instead of setText here is a link.
The setText, delete the previous text and set the text you are giving to it. The append keep the current text in your text area.
Hope it helps!