I have the following code :
private void btnGetListProvince_Click(object sender, EventArgs e)
{
rtbRandomPoint.Clear();
lvProvince.Clear();
try
{
rtbRandomPoint.AppendText("\n" " Successfully get all Province in Viet Nam");
lvProvince.Columns.Add("id", 70);
lvProvince.Columns.Add("name", 150, HorizontalAlignment.Left);
provinces = ProvinceController.getProvinceListByCountry();
for (int i = 0; i <= provinces.Count - 1; i )
{
Province province = provinces[i];
lvProvince.Items.Add(province.Id);
lvProvince.Items.Add(province.Name);
}
}
catch (Exception ex)
{
WarningHelper.ShowExeptionMessage(ex);
}
}
The results when running will produce results like the image below : image
I want to sort by ID column with name column, as my result they are messy.
I tried below but it lost the column Name :
private void btnFilterProvince_Click(object sender, EventArgs e)
{
lvResultCommune.Clear();
rtbResult.Clear();
try
{
rtbResult.AppendText("\n" " Successfully get all Province in Viet Nam");
lvResultCommune.Columns.Add("id", 70);
lvResultCommune.Columns.Add("name", 150, HorizontalAlignment.Left);
provinces = ProvinceController.getProvinceListByCountry();
for (int i = 0; i <= provinces.Count - 1; i )
{
Province province = provinces[i];
lvResultCommune.Items.Add(province.Id);
lvResultCommune.Items[i].SubItems.Add(province.Name);
}
}
catch (Exception ex)
{
WarningHelper.ShowExeptionMessage(ex);
}
}
Anyone have any suggestions for me? thank you !
CodePudding user response:
Just set the View
property to Details
lvResultCommune.View = View.Details;