How can i get the Text from Mouse Right Click? - visual-studio-2005

I use Microsoft Visual Studio 2005. And try to programming with C#
I have a Textfile with Texts. For Example: D23423P 34L211 5 I copy this Text from the Textfile with Mouse Right Click Copy to use this for my 17 TextBoxs. The TextBoxs has the Label: label1.
So i created to label1 a ContextMenuStrip: Paste and Cut:
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
string tempr = Clipboard.GetText(TextDataFormat.Text);
textBox1.Paste(tempr);
}
If i click Paste the Function, i wanna get the Texts (D23423P 34L211 5 ) and fill the 17 TextBoxs for Example:
textBox1: D
textBox2: 2
textBox3: 4
....
I clicked Right Click "Paste" i save the Data text in tempr. How can i set the textBox 1 with D textbox 2 with 2...?
Should i use the Methode String split?

Declare a TextBox array in your class:
private const int TextBoxCount = 17;
private TextBox[] TextBoxArray;
And populate it somewhere in your form's constructor:
TextBoxArray = new TextBox[] { textBox1, textBox2, textBox3... };
In your paste function, loop through the string, and index with []:
for (int i = 0; i < TextBoxCount; i++)
TextBoxArray[i].Text = tempr[i];

Related

Access ListView item text (FMX)

I have a TListView and when the user clicks on the image of an item (big green dot in picture below) i want to copy the item text ("russtest.cfg") and subitem text ("My Device, 1991") to display in a ShowMessage. I can't find how to do it in C++ Builder but this link shows how in Delphi.
Below is the code i've tried in the TListView's ItemClickEx method:
TListItem* item;
item = ListView1->Items->Item[ItemIndex];
UnicodeString s;
s = item->ToString();
ShowMessage(s);
But it brings back this:
EDIT 1: Added the code i use to populate the ListView:
TListViewItem* item2Add = Form1->ListView1->Items->Add();
Form1->ListView1->BeginUpdate();
item2Add->Text = mystring3; // e.g. "russtest.cfg"
item2Add->Detail = mystring2; // e.g. "My Device, 1991"
item2Add->ImageIndex = 1; // big green dot
Form1->ListView1->EndUpdate();
Your need to typecast the TListItem* to TListViewItem*, then you can access its Text property:
TListViewItem* item = static_cast<TListViewItem*>(ListView1->Items->Item[ItemIndex]);
String s = item->Text;
ShowMessage(s);

How to get the XPath of a grid cell using Firebug?

I am working on a UI. My job is to automate it. I came across the following grid.
When you click on any cell under the Rule column, a browse button appears.
I am supposed to automate this scenario. So, using Firebug I am trying to extract the XPath of that cell.
I used Firebug's inspector to locate that particular cell, so that I can write the XPath for it, but I am unable to locate that cell. Instead, the entire row is getting selected, as shown in next images.
How should I approach this problem?
below code might help you to verify the grid values,
public void verifyTableValues(String expectedValue
) {
try {
//List of Fields values which you want to verify
List<String> expectedValues = Arrays.asList(expectedValue.split("#"));
// you will get the number of rows in Table Select the xpath to /tr
String tableRow = driver.findElements(By.xpath(//table row constant));
int tableRwCnt = getCount(tableRow);
// you will get the number of Columns in Table Select the xpath to /td
String tableColumn = driver.findElements(By.xpath(//table Column constant));
int tableColumnCnt = getCount(tableColumn);
for (int cnt = 1; cnt <= tableRwCnt; cnt++) {
for (int listCount = 1; listCount <= tableColumnCnt; listCount++) {
String actualVal = findElement(By.xpath(tableColumn + "[" + cnt + "]/td["
+ expectedValues.get(listCount) + "]").getText();
String expectdVal = expectedValues.get(listCount);
Assert.assertEquals("Value from table doent Match", expectdVal, actualVal);
}
}
} catch (Exception e) {
// code for exception
}
}
Parameter: expectedValue = test1#test2#test4#test4 (Grid values)

xamarin convert entry text to numeric value

I'm new user of Xamarin studio 5.9.5 (build 9) on Windows, and I want make a form based application that involves some mathematical calculations (.Net + Gtk#).
I made a simple form containing 3 Entry widgets (2 for input values and 1 for output value) and 1 button. Here is the code for the button (simple addition Entry3 = Entry1 + Entry2)
using System;
using Gtk;
...
protected void OnBtnClicked (object sender, EventArgs e)
{
entry3.Text = entry1.Text + entry2.Text;
//throw new NotImplementedException ();
}
As you can see, this code just makes a concatenation of both text fields.
How can I convert the text fields into numeric values in order to achieve mathematical addition (and other calculations) ?
Thanks
// assuming these values are ints
int val1 = int.Parse(entry1.Text);
int val2 = int.Parse(entry2.Text);
entry3.Text = val1 + val2;

Appending ="0xxxx" to excel cell while exporting using NPOI to maintain leading zero, or how to set cell as text

I am trying to maintain the leading zeros while exporting a column holding phone numbers to excel using NPOI in an asp.net mvc 3 application. I have read here; http://creativyst.com/Doc/Articles/CSV/CSV01.htm#CSVAndExcel that I can append ="[some number beginning with 0]" to have excel maintain the zeros. I have also read that if I set the cell as text it will maintain the zero. I have been unsuccessful in my attempts to do this. Here is my code;
public ActionResult Export(int page, string orderBy, string filter)
{
//Get the data representing the current grid state - page, sort and filter
GridModel model = Model().ToGridModel(page, 10, orderBy, string.Empty, filter);
var orders = model.Data.Cast<Advertiser>();
//Create new Excel workbook
var workbook = new HSSFWorkbook();
//Create new Excel sheet
var sheet = workbook.CreateSheet();
//(Optional) set the width of the columns
sheet.SetColumnWidth(0, 10 * 256);
sheet.SetColumnWidth(1, 50 * 256);
sheet.SetColumnWidth(2, 50 * 256);
sheet.SetColumnWidth(3, 50 * 256);
//Create a header row
var headerRow = sheet.CreateRow(0);
//Set the column names in the header row
headerRow.CreateCell(0).SetCellValue("Name");
headerRow.CreateCell(1).SetCellValue("Phone");
headerRow.CreateCell(5).SetCellValue("Company Name");
headerRow.CreateCell(7).SetCellValue("Address 1");
headerRow.CreateCell(8).SetCellValue("Address 2");
headerRow.CreateCell(9).SetCellValue("Address 3");
headerRow.CreateCell(10).SetCellValue("Address 4");
headerRow.CreateCell(11).SetCellValue("Post Code");
headerRow.CreateCell(14).SetCellValue("Email");
headerRow.CreateCell(16).SetCellValue("Website");
headerRow.CreateCell(19).SetCellValue("Listing Type");
//(Optional) freeze the header row so it is not scrolled
sheet.CreateFreezePane(0, 1, 0, 1);
int rowNumber = 1;
//Populate the sheet with values from the grid data
foreach (Advertiser order in orders)
{
//Create a new row
var row = sheet.CreateRow(rowNumber++);
//Set values for the cells
row.CreateCell(0).SetCellValue(order.AdvertiserName);
row.CreateCell(1).SetCellValue(order.Phone);
row.CreateCell(3).SetCellValue(order.CompanyName);
row.CreateCell(5).SetCellValue(order.Address1);
row.CreateCell(6).SetCellValue(order.Address2);
row.CreateCell(7).SetCellValue(order.Address3);
row.CreateCell(8).SetCellValue(order.Address4);
row.CreateCell(9).SetCellValue(order.Postcode);
row.CreateCell(10).SetCellValue(order.AdvertiserEmail);
row.CreateCell(11).SetCellValue(order.Website);
row.CreateCell(12).SetCellValue(order.listing.type);
}
//Write the workbook to a memory stream
MemoryStream output = new MemoryStream();
workbook.Write(output);
//Return the result to the end user
return File(output.ToArray(), //The binary data of the XLS file
"application/vnd.ms-excel", //MIME type of Excel files
"Advertisers.xls"); //Suggested file name in the "Save as" dialog which will be displayed to the end user
}
}
I have tried the setCellTyoe method in various places with no luck.
I don't mind how it's done, I just want to maintain the leading zeros when the sheet is exported.
I can not test this but did you try setting the type in the createCell call? If all else fails you could resort to the tried and true hack of putting a single quote before the leading zero:
'00185
This will force the cell to text and excel should only display it on edit.
Changed the data type from string to int and NPOI set the cell as text, keeping the leading zero.

Create Excel Add-in - get cell value

I am creating a excel Add-in using visual studio 2010. I was able to get the cell address using this code.
label1.Label = Globals.MyAddIn.Application.ActiveCell.Address.ToString();
I want to get the cell value. Also if you can tell me how to set a value for a given cell.
Please help.
to get a cell value for the active cell the following should do it
var cellValue = Globals.MyAddIn.Application.ActiveCell.Value.ToString()
or for a specific cell
var cellValue = Globals.MyAddIn.Application.Cells("A1").Value.ToString()
To Set the value it is basically the reverse
Globals.MyAddIn.Application.Cells("A1").Value = "ABC123"
EDIT
Try this. I know that this works as I have something like it working in my own addin.
int row = 1;
int col = 1;
var sheet1 = (Excel.Worksheet)Application.ActiveWorkbook.Worksheets["Sheet1"];
sheet1.Cells[row, col] = "ABC123";
string cellValue = sheet1.Cells[row,col];

Resources