Ejemplo n.º 1
0
        private void taidalist()
        {
            if (dataGridViewCountry.SelectedCells.Count == 1)
            {   // otsime valitud rea riigi nimetus
                int selectedrowindex = dataGridViewCountry.SelectedCells[0].RowIndex;

                DataGridViewRow selectedRow = dataGridViewCountry.Rows[selectedrowindex];

                label1.Text = Convert.ToString(selectedRow.Cells[0].Value);



                List <City> city = new List <City>();
                city = CountryDB.GetAllCitiesbyCountryName(label1.Text);

                DataTable table = new DataTable();

                DataColumn idColumn = table.Columns.Add("Name", typeof(string));
                table.Columns.Add("District", typeof(string));

                table.Columns.Add("Population", typeof(long));

                table.PrimaryKey = new DataColumn[] { idColumn };

                foreach (City c in city)
                {
                    table.Rows.Add(new object[] { c.Name, c.District, c.Population });
                }
                table.AcceptChanges();
                dataGridViewCity.DataSource = table;
            }
        }
Ejemplo n.º 2
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            List <City> city = new List <City>();

            city = CountryDB.GetAllCitiesbyCountryName(comboBox1.Text);

            DataTable table = new DataTable();

            //DataColumn idColumn = table.Columns.Add("Name", typeof(string));
            table.Columns.Add("Name", typeof(string));
            table.Columns.Add("District", typeof(string));

            table.Columns.Add("Population", typeof(long));

            //table.PrimaryKey = new DataColumn[] { idColumn };

            foreach (City c in city)
            {
                table.Rows.Add(new object[] { c.Name, c.District, c.Population });
            }
            table.AcceptChanges();
            dataGridView1.DataSource = table;
        }