I have a series of mutator methods in another class, each of which is linked to a textBox.
(ClassA). Now, I am using an object of ClassA (myClassAObject.setFirstName(param here), to set the text, so the contents of that parameter will display in that textbox.
The content of that mutator method is as follows:
public void setFirstName (string newFirstName)
{
txtBoxFirstName.Text = newFirstName;
}
I know that the mutator works correctly, because otherwise I'd not see the first name of the patient, I'd see "null", or in the case of a println, a blank space.
The question is below this line
The mutator method, for some reason is not causing the textBox to display the text it is given in a parameter, when I access it from the other class. The textBox remains blank. How can I get it to work correctly? I have used MessageBoxes to check if there is a value for the textBox to display, and yes, the contents of the variable appear onscreen.
Here is how the parameter is passed from the second class, to the class in which the textBox resides:
myClassAObject.setFirstName(firstName);
The code above is example code, but it illustrates what I am doing.
Below is the actual code.
Firstly, from the class where the textBox resides.
Secondly, where the new parameter is being passed from.
public void setPatientFirstName(string newPatientFirstName)
{
txtBoxPatientFirstName.Text = newPatientFirstName;
}
Second part of code:
patientRecordClassOverseer.setPatientFirstName(patReaderFirstName);
I am using a "Reader" (OleDB) to read the data from the database. It is working, as I have MessageBoxes setup for debugging purposes.
Related
I have been working on an assignment with forms for a while now and everything works, however my professor want us to devide everything in seperate classes.
So what I have now is:
MainForm.cs
MainForm.Designer.cs
MainForm.resx
program.cs
In the MainForm.cs is where i have all my code and where i call the buttons, labels, textboxes etc from.
What I want to do, is to have a strucutre with other classes such as
MainForm.cs
MainForm.Designer.cs
MainForm.resx
program.cs
class1.cs
class2.cs
I tried doing this, but from my class1 i couldn't call the Design(name) of the Form since it dont exist in the context. I have been searching a lot but haven't found anything that matched my problem or how to solve it.
How can I solve this problem?
For any property to be accessible from another class (another form for instance as Form itself is a class), the property must be public, so for example lets say you have a textbox named txtSomething and you need to access its text, you may create a public property that lets you get and set its Text property:
public string SomeProperty { get { return txtSomething.Text;} set {txtSomething.Text = value;}}
You can of course change MainForm.Designer.cs and make all controls (for example textboxes) public where they are defined, but it is not a good choice at all. because you should always give public access only where it is needed. for example if you need a controls text, let just its text property be accessible (the code above).
Even, if the second form has just to get the textbox value and does need to set it, you may give a readonly access. so the code above would be:
public string SomeProperty { get { return txtSomething.Text;} }
Then assuming that the instance of FrmMain is frmMain you can access the Text property of that textbox like:
string propertyValue = frmMain.SomeProperty;
I have a method below where I enter in a postcode, select the find address button and I expect some fields to be visible:
public void CompletePostcodeLookup()
{
_driver.FindElement(PaymentDetailsResponsiveElements.PostcodeLookupField).SendKeys("LS11 9AW");
_driver.FindElement(PaymentDetailsResponsiveElements.FindAddressBtn).Click();
_driver.WaitToBeInvisible(PaymentDetailsResponsiveElements.FindAddressBtn, 5);
_driver.WaitToBeVisible(PaymentDetailsResponsiveElements.AddressManualHouseNumberField, 5);
_driver.WaitToBeVisible(PaymentDetailsResponsiveElements.AddressLineOneField, 5);
_driver.WaitToBeVisible(PaymentDetailsResponsiveElements.AddressCityField, 5);
_driver.WaitToBeVisible(PaymentDetailsResponsiveElements.AddressManualPostcodeField, 5);
_driver.WaitToBeVisible(PaymentDetailsResponsiveElements.AddressCounty, 5);
}
Now not only am I expecting the fields to be visible, but these fields should be valld and in the HTML we can determine these fields are valid based on this...
<input... aria-invalid='false'>
So what i did in my PaymentDetailsResponsiveElements.cs page is included a method that finds any input that contains this:
public static By ValidFields => By.XPath("//input[#aria-invalid='false']");
Now this may be the icorrect way of doing things but I wanted to know that if I wanted to check that all of these visiable fields are valid, what is the correct way to code it? Should i even place them in an 'Assert'?
Edit:
I included all methods into one method, if I can do an assertion based on none of these methods have an invalid field then should be ok:
public void CompleteContactDetailsForm()
{
SelectBookingContact();
CompletePostcodeLookup();
CompletePhoneNumberFields();
CompleteEmailAddressFields();
}
Thanks
1st way:
You may consider writing a for loop to check that each webElement has value: invalid='false' (you may do this by writing simple parser)
2nd way:
You can do it by reading complete list of desired Web elements in an Array List and iterate through it using iterator like here
Regarding Assert, that should be placed on final step (.cs file where you are calling this case).
I want to get the data from a cell from a selected row, in a gridView, and bring it into another form, inside a textEdit that then edit the row of the selected cell, the problem is that when using
var cacca = this.gridView.getFocusedRow() as PartnersMissing;
MessageBox.show(cacca.toString())
the messageBox writes Test01.parnersMissing, where Test01 is the name of the project and I really don't know why PartnersMissing is there. What is wrong in this code?
The datagrid has data from an sql database and it is made with DevExpress.
Please don't mind the names for the variables if you know italian, I was in a hurry :D
The current row can be obtained using the GridView's
GetFocusedRow method. This method returns an object whose actual
type is determined according to the data source.
If you are binding it with a List<PartnersMissing> objects then you are getting correct value from the GetFocusedRow method. If you want to access the property of the current row object then you can simply do it.
for example: PartnersMissing has property ABC then you can access as below:
var cacca = this.gridView.getFocusedRow() as PartnersMissing;
MessageBox.show(cacca.ABC)
ToString() method returns the type of the object not any property value. you just printing type of the object rather than accessing property of object.
As Dimitry Says, You can also access particular column value or row' PartnersMissing object property using the GetFocusedRowCellValue(String) Method.
As far as I can see from your code, the result is expected because the cacca.toString() expression return the type name for those types, which do not override the standard object.ToString method.
To show something helpful, you should either to override this method
class PartnersMissing {
public string Name { get; set; }
public override string ToString(){
return Name;
}
}
or to obtain the specific values from your object's fields:
MessageBox.Show(cacca.Name);
You can also to obtain the object's fields value directly from the gridView:
string name = gridView.GetFocusedRowCellValue("Name");
I have created custom extraction rule and the property i need the properties to be data driven i.e. I want to attach a data source (CSV file). how do I go about it ?
Followings are the screen shots and code snippets that describes the problem
Code snippet for custom extraction rule class
public class CustomeExtractionClass : ExtractionRule
{
public string Name
{
get;
set;
}
public override void Extract(object sender, ExtractionEventArgs e)
{
// Code to extract text/values from Response Based On NAME(i.e. Property) value
received from UI
}
}
UI for Name property
Note : Textbox next to Name property
How do I make it Data driven ? just like the one we get while inserting FormPost parameters... here is the example
Note the dropdown button bottom right which pulls up the attached data sources... I want the Name property values to be attached to the same data source.... how do i go about it ???
Finally after spending many hours I was able to get the values from the CSV file into my custom extraction rule. I could not bind the CSV file column to the Extraction rule property, however i got the work around. here is what i was missing
[DataBinding("DataSource1", "mycsvfile#csv", "ProcessInstanceID", "MyProcessInstanceID")]
here are the steps to achieve it
Step 1 : Add data Source to WebTest (Skip if already added)
Step 2 : Generate Code from WebTest (Skip if already done)
Step 3 : Bind datasource (i.e. CSV file) columns by adding following lines of code just above the declaration of your webtest class.
[DataSource("DataSource1", "Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\customextractionrule\\mycsvfile.csv", Microsoft.VisualStudio.TestTools.WebTesting.DataBindingAccessMethod.Sequential, Microsoft.VisualStudio.TestTools.WebTesting.DataBindingSelectColumns.SelectOnlyBoundColumns, "mycsvfile#csv")]
[DataBinding("DataSource1", "mycsvfile#csv", "ProcessInstanceID", "MyProcessInstanceID")]
public class WebTest2Coded : WebTest
{
Note : in above code "MyProcessInstanceID" is the name of context parameter which will be created by visual studio and value of CSV file column will be assigned to this context parameter. you can give any name you wish.
Step 4 : Access the value of the Context parameter in your custom extraction rule
public override void Extract(object sender, ExtractionEventArgs e)
{
string ProcessIDinCSvFile = e.WebTest.Context["MyProcessInstanceID"].ToString());
To set the context parameter to the text within the field just enter the full name of the data source field enclosed in doubled curly braces into the field. The correct form of text is shown circled in red in an image in the question, namely {{DataSource1.mycsvfile#csv.ProcessInstanceID}}.
Data source fields can also be accessed directly from the context by code such as
string theText = e.WebTest.Context["DataSource1.mycsvfile#csv.ProcessInstanceID"].ToString();
If the Name field of the extraction rule is set to the name of a content parameter (ie not to its value) then the current value can be read out and a new value inserted with code like
string theText = e.WebTest.Context[Name].ToString();
e.WebTest.Context[Name] = "The new string";
I got a problem with ListView in System.Windows.Forms, that i can't handle it on myself, begging for help or a hint where do I do wrong?
Description:
- I have a class - name it cListViewItem ('c' from custom), that inherits from standard ListViewItem, but stores my own data handling class. Now, after adding cListViewItem to a ListView class using ListView.items.Add( ) i don't seem to have any control over the item's name.
- fragments of my source (lil changed for the purpose of this post)
using System.Windows.Forms;
cListViewItem:ListViewItem
{
// gives a basic idea
public cListViewItem( myclass DataStorage )
{
// constructor only stores DataStorage to a local variable for further use;
this._storage = DataStorage;
}
protected myclass _storage;
// and there goes the fun:
// I thought that ListView class uses .Text property when drawing items, but that is not truth
// my idea was to 'cheat' a little with:
new public String Text
{
get
{
// overriding a getter should be enough i thought, but i was wrong
return( some string value from DataStorage class passed via constructor );
// setter is not rly needed here, because data comes from this._storage class;
// in later stages i've even added this line, to be informed whenever it's called ofc before return( ); otherwise VisualStudio would not compile
MessageBox.Show( "Calling item's .Text property" );
// guess what? this message box NEVER shows up;
}
}
}
I see that's important to use .Text setter, but constructor is the last moment i can do it, right after creation cListViewItem is being added to ListView Items property and displayed, so there's no place to call .Text = "" again.
My piece of code only works when I set all things in cListViewItem 's constructor like:
public cListViewItem( myclass DataStorage )
{
this._storage = DataStorage;
this.Text = DataStorage.String1;
// and if I add subitems here, I will see em when the ListView.View property be changed to View.Details
}
So am I blind or what? when I use cListViewItem.Text = "string" I will see 'string'
in the ListView but when I just override .Text getter i can't see the items :(
ListView class gives the flexibility of showing items the way I need. I wanted to create a class that will bind my custom data storage class with a ListView class. In the next stage of my application I want to bind a form for selected item in a ListView, that will allow me change item's (my custom class) values. That's why i wanted to make each ListViewItems item remembering corresponding custom data storage class.
Names shown in ListView will never be uniqe, so multiple same names all allowed, but items will differ by a id value (database-wise);
I just can't figure out why using ListViewItem.Text setter does the job, altho ListView class does not use ListViewItem.Text getter for displaying items (my MessageBox never pops up)??
Pls help.
The main problem here is that you are hiding the property with the new keyword. The original property is not virtual ("overwritable") so it is NOT overwritten but shadowed.
Read here for more information.
If I understand correctly, then the following points might be helpful.
For storing custom data you don't actually need to derive from the ListViewItem class, instead you can use an instance of a ListViewItem and set the Tag property to any object, this can be your DataStorage class. If you do this, then after you've constructed the ListViewItem set the Text of it
DataStorage storage = GetDataStorage();
ListViewItem item = new ListViewItem(storage.Name);
item.Tag = storage;
If you are going to inherit the ListViewItem then set the value in the constructor
public cListViewItem( myclass DataStorage )
{
// constructor only stores DataStorage to a local variable for further use;
this._storage = DataStorage;
this.Text = this._storage.Name;
}
Property and Method hiding gets a little confusing for myself at least, I can't quite remember the rules, but ultimately the call to Text that is done automatically is not going to be calling your version...