jeudi 2 avril 2015

Passing datagridview data

I am currently writing a program which needs an edit form. This form is to edit a country in the datagridview which I have. I am however confused about how to pass the data from the data gridview in the main form to the relative places on the edit form. I have done most of the coding as shown below. I know I need a method in my AVL class to return all the information of the selected country back to the main form method which then passes it back to the edit form and displays it. If anyone can help me to complete this method I would be grateful, I am unsure what to pass and what to write in this method.


Main form method



public void button2_Click(object sender, EventArgs e)
{
// creates new form referencing data grid view and AVL Tree
EditCountryForm editform = new EditCountryForm(ref this.countryTree, dataGridView1);

string CountryName = "";

//set name of country selected to string
foreach (DataGridViewRow item in this.dataGridView1.SelectedRows)
{
CountryName = item.Cells[0].Value.ToString();

}

// create new country with that name
Country FindRow = new Country(CountryName, 0, 0, 0, 0,null);
// create new country to be passed to edit form
Country EditCountry = countryTree.ReturnCountryInfo(FindRow);

editform.passCountry(EditCountry);

editform.Show(); // Shows Form


Edit Form Method



public void passCountry(Country SelectedCountry)
{
this.ToEdit = SelectedCountry;

CountryNameText.Text = ToEdit.name;
CountryText.Text = ToEdit.Name;
GDPGrowthText.Text = ToEdit.GdpGrowth.ToString();
InflationText.Text = ToEdit.Inflation.ToString();
HDIRankingText.Text = ToEdit.HdiRankings.ToString();
TradeBalanceText.Text = ToEdit.TradeBalance.ToString();


}


AVL Tree method



public Country ReturnCountryInfo(Country FindRow)
{
// Needs to return all information about the selected country

Country SelectedCountry = new Country("", 0, 0, 0, 0,null);
return SelectedCountry;
}

Aucun commentaire:

Enregistrer un commentaire