Reputation: 65
[edit]
calling the follows directly is not possible in my code:
void control_Changed(object sender, EventArgs e)
This function is loop through a Collection of DropDownListBox, and each DropDownListBox has different Select_Change function. Also they are not in the same page, they collection of DropDownListBox is come from different user control of the page.
I saw a lot of solution are simply calling the function that the event should trigger.. But this will not be working on my case.
I have a code that will mapping the data to a collection of dropdownlistbox and select the proper dropdownlistbox item for each dropdownlistbox.
So, is kind of like this:
foreach (Control aControl in aControlCollection){
if (aControl.GetType() == typeof(RadComboBox))
{
bool FoundItem = false;
RadComboBox aComboBox = (aControl as RadComboBox);
foreach (RadComboBoxItem aComboItem in aComboBox.Items)
{
Debug.WriteLine("aComboItem " + aComboItem.Text + " Value" + aComboItem.Value);
if (aComboItem.Value.ToLower() == _dataObject.ToString().ToLower())
{
//aComboBox.SelectedIndex = aComboBox.Items.IndexOf(aComboItem);
aComboItem.Selected = true;
FoundItem = true;
~~~FIRE EVENT HERE~~~~~
//break;
}
else {
aComboItem.Selected = false;
}
}
if (!FoundItem)
{
RadComboBoxItem aComboItem = new RadComboBoxItem();
aComboItem.Value = _dataObject.ToString();
aComboItem.Text = _dataObject.ToString();
aComboBox.Items.Add(aComboItem);
aComboBox.SelectedIndex = aComboBox.Items.IndexOf(aComboItem);
}
}
}
}
Normally in the page, when user select the a first dropdownbox, the 2nd dropdownbox that follows will generate the proper dropdownlist item according to the first dropdownbox (from the first dropdownbox selectindexchange event).
So I wonder if there is anyway I can fire the DropDownListBox programmatically?
Just to make it even more clear, the above function is call by iterates all DropDownListBox on the page, so they can be link into different function.
Upvotes: 1
Views: 680
Reputation:
If you were to use the traditional void control_Changed(object sender, EventArgs e)
code...
if (aComboItem.Value.ToLower() == _dataObject.ToString().ToLower())
{
//aComboBox.SelectedIndex = aComboBox.Items.IndexOf(aComboItem);
aComboItem.Selected = true;
FoundItem = true;
control_Changed(aComboItem, new EventArgs());
}
void control_Changed(object sender, EventArgs e) {
// your code here
}
Upvotes: 0
Reputation: 33108
Combobox_SelectedItem(null, null);
You can forge any arguments you desire into the parameters, if needed.
Upvotes: 1