My code is trying to delete IExplorer history from the registry! The typed URLs are stored in a checked listbox, i can delete one value at a time both in the registry and from the checked listbox but when i try deleting multiple items at a time it doesn't work? here is the code
privatevoid Delete_Click(object sender, EventArgs e)
RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\TypedURLs", true);
string v = key.GetValueNames();
string t = new string[v.Length];
int count = checkedListBox1.Items.Count;
for (int i = 0; i < v.Length - 1; i++)
t[i] = (string)key.GetValue(v[i]);
if(t[i] == (string)checkedListBox1.SelectedItem)
for ( int i = count; i >0; i--)
if (checkedListBox1.CheckedItems.Contains(checkedListBox1.Items[i - 1]))
checkedListBox1.Items.RemoveAt(i - 1);
SelectedItem is one item, use SelectedItems to get all selected items:
Add also this in the constructor:
checkedListBox1.SelectionMode = SelectionMode.MultiExtended; // a user can select multiple items using the CTRL key, SHIFT key and the arrow keys// OR:
checkedListBox1.SelectionMode = SelectionMode.MultiSimple; // if a user clicked on a selected item in the list box, that item will be deselected, and if the user clicked on a deselected item in the list box, that item will be selected
Hope this helps.
In some cases, my signature will be longer than my message...
Well it means that when there are all the items in the checkedlistbox selected and i press the delete button they get deleted from the checkedlistbox but not from the registry...i cand only delete values from the registry one at a time and only when there are more than 2 entries..
If you had stepped over your code, you would have seen what the problem is. Basically, you're iterating over one list of values, and you're getting one single value from the other list to compare it to. Try iterating over the selected items from the list box as well, and do your comparison in there.
Now, a more important point is that your comparison code is using terrible variable names. I ended up getting confused by your t and v variables.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington