Cannot select the ComboBox item - c#

I have two Comboboxes where the second one is dependent upon the first one.
When the SelectedIndexChanged event of the first Combobox fires then the second Combobox will be enabled.
After the event, the second Combobox is enabled but I cannot select the ComboBox item.
EDIT
I use Dev express Tools
First Combo I load in Page_Load Event
I use Server Side code:
protected void ASPxComboModule_SelectedIndexChanged(object sender, EventArgs e)
{
LoadSecondCombo();
LoadSecondCombo.Focus();
}
There is no problem in loading, but I'm unable to select 2nd combo item.

What do this do: LoadSecondCombo(); I assume it returns an instance of the control. Where does it set combo.Enabled at?

LoadSecondCombo(); LoadSecondCombo.Focus();
look like method that reference your comboBox and Load it.
When you want to focus LoadSecondCombo should ne an instance of Combo Box. I think it is not and so your combo is not selected.
Can you try going back a bit and look at the Id of combo Box (if it in a composit control like DataGrid / View you will have to do a FindControl) and then focus. I mean typing
comboBtn1.Focus();
Now if that works then you know that your control can be found. In that case mofidify the LoadSescondCombo() to return an instance of combo button if it is not doing so already.
then create a reference to that combobutton by
ComboButton cbtn = LoadSecondCombo(); and
cbtn.Focus();

Related

Need help in a school programming internal

I have two lists called standards and credits. The standards list is added to a ComboBox. When I click an item in the ComboBox I want to be able to show an item in the credits list. For example I click first index in the ComboBox, I want to show item in the first item of the credits list. I have this code but it gives me an error I can't fix it. This is the error im getting:
System.ArgumentOutOfRangeException
It's from this line of code
lblCredits.Text = credits.ElementAt(standard.IndexOf(cboStandard1.Text))
-
private void cboStandard1_SelectedIndexChanged(object sender, EventArgs e)
{
if (cboStandard1.SelectedIndex + 1 > 0)
{
lblCredits.Text = credits.ElementAt(standard.IndexOf(cboStandard1.Text));
}
}
This is showing that my lists are the same length
private void standardlist()
{
standard.Add("91632");
standard.Add("91633");
standard.Add("91634");
standard.Add("91635");
cboStandard1.DataSource = standard;
((ComboBox)cboStandard1).SelectedIndex = -1;
credits.Add("4");
credits.Add("6");
credits.Add("4");
credits.Add("4");
}
Like I said, binding the ComboBox, i.e. setting its DataSource property, will select the first item by default, which will raise the SelectedIndexChanged event, which will execute your code. That all happens before you've populated the credits list, which is why it contains no items. There are two things you can do, and you may choose to do both:
Populate the credits list before setting the DataSource of the ComboBox.
Handle the SelectionChangeCommitted event instead of SelectedIndexChanged.
The SelectionChangeCommitted event is raised only when the user selects an item via the UI, so it will not be raised when you bind the data and then reset the SelectedIndex, while SelectedIndexChanged will be raised twice. Even if you do implement option 1, you'll still have an issue on the second SelectedIndexChanged event because you'll be passing -1 to ElementAt, so you'll get an ArgumentOutOfRangeException thrown.

Telerik Searchable radcombobox not repopulating after item is selected

I have a RadComboBox that allows for custom searching for about 1500 records. Once one is selected the User control changes accordingly. If I were to want to select a new record, the selected record is the only record that displays and when you type in the search field, nothing is found either.
However, if you select a record, do what you need then click the drop down then click off it then click on it again, it resets itself as desired. How can I make it so the drop down list populates itself on the initial click?
Probably you are losing the datasource.
On the SelectedIndexChange event, you can repopulate the datasoure and set currently selected value from arguments that are passed to this event.
So in a pseudocode it would look like:
procedure OnSelectedIndexChanged(object sender, SelectedIndexChangedEventArgs e)
{
var selectedValue = e.Value;
(sender as RadComboBox).DataSource = YourMethodToGetDatasource();
(sender as RadComboBox).DataBind();
(sender as RadComboBox).SelectedValue = selectedValue;
}
and yes i know currently pseudo code doesn't look so pretty but of course you will need to use the id of your control in place of (sender as RadComboBox).
If someone know a better method for this i would be glad to gain this knowledge :)

best way to handle datagridviecomboboxColumn selected index change

I have a problem on my datagridview containing datagridviecomboboxColumn. i need fire a selectedindex change event after the user selected new items from the combobox. how can i do that? i have a work around but it seems lik it might not be correct:
Datagridview1_CellValueChanged(object sender, DataGridViewRowCancelEventArgs e)
but it only fire after the user leave the cell where the combo box were position,what i need is an event like selectedindex change.
Please help me to solved this problem. thanks ;)
From the MSDN: Unlike the ComboBox control, the DataGridViewComboBoxCell does not have SelectedIndex and SelectedValue properties. Instead, selecting a value from a drop-down list sets the cell Value property.
So CellValueChanged seems like the way to do it.
If you want to it without the user having to leave the cell, you can use CurrentCellDirtyStateChanged.

How to solve this combo box issue in datagridview in .net winforms?

i had two combobox(Catogery, product) in my grid.
what i want to do is.
if i select category it will display some data set value based on category,
and if i select product it will bind some values in that datagrid cells.like price quantity..
i don't have idea about how to write event for combo box selected index change event which is inside the grid.
Handle the CellEndEdit event on the DataGridView. You'll have to test that the sender is the correct DataGridViewComboBoxColumn, read the value, and use that to bind the other DataGridViewComboBoxColumn to the appropriate data source.
I'm not sure about that, because I don't have visual studio at the moment. But there must be an event called RowCellValueChanged event, write your code in this event, hand row index with EventArgs e and set your values to row which you have an index of row.

.Net C# windows forms, listbox control question

I have a pretty simple form with a listbox, a text box, and two buttons.
The list box items are populated from a sql database table. The user may chose to select one or multiple items from the listbox.
The text box is used to write more details about the items in the listbox. One button can then be clicked to update another database table with these details.
I want to make it where if any items are selected from the listbox, those contents are automatically copied into the text box field on the fly as they are selected.
Is this possible?
I've been able to make this happen on the button click event - just not on the fly as they are selected. I want it to occur before the additional details are being sent to the database
I've also tried using several different listbox events, but have been unable to obtain the results I am looking for.
Any suggestions?
try this out
you will have to handle the SelectedIndexChanged event on the listbox.
here is an example with example controls.
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = "";
foreach (string nextitem in listBox1.SelectedItems)
{
textBox1.Text += nextitem + " ";
}
}
im not too sure HOW you want the text to appear in the textbox so that would be up to you in the foreach loop.
yes, the SelectedIndexChanged event fires on every selection change, and you can concatenate together the items in the listbox. But if you are talking the description that's not visible too, you need to store the description in each listboxitem tag property, and in your code retrieve the description from there.

Categories

Resources