checkedListBoxControl1_ItemCheck Distinguish between user check AND
programmatically checked
I have a checked list and when the program loads, I need to load a list of
string and boolean to the checklist box. But whilst setting the booleans
this.mediaCenter.ItemManager.SetDirectoryCheck(index, isChecked);
checkedListBoxControl1_ItemCheck Fires. I dont want that because when it
fires, it refreshes my database and takes a long time to complete. I only
want it to fire if user changes the checked list Check state.
Note: I have
Presently I am using A flag to do that and its ugly and giving me a lot of
problems else here
private void checkedListBoxControl1_ItemCheck(object sender,
DevExpress.XtraEditors.Controls.ItemCheckEventArgs e) //fires second
on check
{
int index = e.Index;
bool isChecked = e.State == CheckState.Checked;
this.mediaCenter.ItemManager.SetDirectoryCheck(index, isChecked);
if (this.IsUserClick)
BuildDatabaseAsync();
this.IsUserClick = false;
}
private bool IsUserClick;
private void checkedListBoxControl1_Click(object sender, EventArgs e)
//Fires first on check
{
if (checkedListBoxControl1.SelectedItem == null) return;
IsUserClick = true;
}
May be my approach of filling the Listbox Control is strange in the first
place. But due to a lot of unwanted changes along the path. I do it as
follows
private void BuildCheckListControl(string[] dirs)
{
IsUserClick = false; "directories reources" and prevent UI from
updating
this.checkedListBoxControl1.DataSource = dirs;
for (int i = 0; i < dirs.Length; i++)
checkedListBoxControl1.SetItemChecked(i, checkedList[i]);
}
checkedList[] contains an array of booleans corresponding to the dirs arrays
No comments:
Post a Comment