jeudi 2 avril 2015

How to group and rowFilter a column

my datagridview get it records from a database and looks like this:



[Country]
Gh
Ng
Sa
Gm
Sw
Ru


I wanna now Filter this column using a combobox. I' ve two values in my combobox Africa and Europe. My expectation is to get something like this:



//If i select Africa in the combobox
Gh
Ng
Sa
// And if i select Europe
Gm
Sw
Ru


That's my code so far:



private void combobox1_SelectedIndexChanged(object sender, EventArgs e)
{

try
{
//Check an see what's in the dgv
DataView dv = new DataView(dt);
dv.RowFilter = "[Country] LIKE '%" + combobox1.Text.Trim() + "%'";
datagridview1.DataSource = dv;
}
catch (Exception)
{
MessageBox.Show("Column not found", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

}


How can i group them and implement it?


Aucun commentaire:

Enregistrer un commentaire