M
mp
given a listview with checkboxes
user checks some items
list of checked items is saved to xml
user checks or unchecks other items
list of previous choices is readback from xml
(either on button click or next program run)
how *best* to set the items in listview.Item[x].Checked = true
based on items in retrieved list?
heres' what i'm trying (seems to work but probably not right way)
private void lvCriteriaList_ItemCheck(object sender,
System.Windows.Forms.ItemCheckEventArgs e)
{
if (_ignoreCheck) return;
...
}
private void ResetCriteriaChoicesListview(List<Criteria> criteriaChoiceList)
{
Debug.Print("Turn Listview.ItemCheck event off");
_ignoreCheck = true;
ClearCriteria();
Debug.Print("Set checks to stored values");
foreach (Criteria criteria in criteriaChoiceList)
{
for (int i = 0; i < this.lvCriteriaList.Items.Count; i++)
{
if
(this.lvCriteriaList.Items.SubItems[1].Text==criteria.Key )
{
this.lvCriteriaList.Items.Checked = true;
break;
}
}
}
Debug.Print("Turn event back on");
_ignoreCheck = false;
}
private void ClearCriteria()
{
for (int i = 0; i < this.lvCriteriaList.Items.Count; i++)
{
this.lvCriteriaList.Items.Checked = false;
}
}
comments?
thank
mark
user checks some items
list of checked items is saved to xml
user checks or unchecks other items
list of previous choices is readback from xml
(either on button click or next program run)
how *best* to set the items in listview.Item[x].Checked = true
based on items in retrieved list?
heres' what i'm trying (seems to work but probably not right way)
private void lvCriteriaList_ItemCheck(object sender,
System.Windows.Forms.ItemCheckEventArgs e)
{
if (_ignoreCheck) return;
...
}
private void ResetCriteriaChoicesListview(List<Criteria> criteriaChoiceList)
{
Debug.Print("Turn Listview.ItemCheck event off");
_ignoreCheck = true;
ClearCriteria();
Debug.Print("Set checks to stored values");
foreach (Criteria criteria in criteriaChoiceList)
{
for (int i = 0; i < this.lvCriteriaList.Items.Count; i++)
{
if
(this.lvCriteriaList.Items.SubItems[1].Text==criteria.Key )
{
this.lvCriteriaList.Items.Checked = true;
break;
}
}
}
Debug.Print("Turn event back on");
_ignoreCheck = false;
}
private void ClearCriteria()
{
for (int i = 0; i < this.lvCriteriaList.Items.Count; i++)
{
this.lvCriteriaList.Items.Checked = false;
}
}
comments?
thank
mark