Clearing a dropdown menu in VB.Net - vb.net

I have two drop down boxes in my program. When you select an item from the first drop down, it populates select-able items in the second. When I select something in the second and then change the selection in the first one, the values remain in the second. How do I "reset" the second drop down when the first is changed?
Any help would be awesome!
The drop down is in a windows form.

You have to reset the comboxBox items collection before adding the new items :
comboBox.Items.Clear()
Hope that helps.

I'm working with very old VB.NET legacy code in an ASP.NET project, so I'm not sure if this answer will help anyone or not. Here is what I did to clear our dropdown list:
ddlCategory.ClearSelection()
The code in the .aspx file looks like this:
<asp:DropDownList ID="ddlCategory" runat="server" Style="width:250px">
ClearSelection() did exactly what I needed it to do. It cleared the dropdownlist selection so that nothing was selected. The box was blank, but when you dropdown the list, all the options are still available to choose from.

Related

How to Update the Values of a Dropdown in a Subform when the Main Form Changes

I have two forms:
InterviewMaster and InterviewDetail
InterviewDetail opens up as a subform in InterviewMaster and these two forms are linked through a common field called InterviewID
In InterviewDetail I have a textbox called Questiontype as well as combobox called InterviewDropdown.
The data in the dropdown varies based on the data on in the textbox. To make this happen, I have a next button to move to the next question. Whenever I click on next the following runs:
Dim ctlCombo As Control
Set ctlCombo = Forms!InterviewDetail!cmbInterviewDropdown
ctlCombo.Requery
The Row Source setting for my combobox is set to look up the required answers, again this is based on the value as per the textbox:
SELECT [queryAnswerOptions].[Answer] FROM queryAnswerOptions ORDER BY [Answer];
So the options are determined by my query called queryAnswerOptions
So as I cycle through my questions using my next and previous buttons, the dropdown options are updated based on the value of my textbox. This works perfectly when I open the subform from the navigation pane. However, when I open the main form and click on the next button my dropdown does not have any values. I've tried requerying the subform with no luck. I've also tried opening the subform in full screen from my main form but this also does not work. I also don't want to go that route as it does not work well with the overall flow of my form.
Any assistance will be greatly appreciated.
Problem with the query WHERE criteria parameter is when form is installed as a subform, the form reference no longer works because it must use the subform container control name. I always name container control different from the object it holds, such as ctrDetails.
Option is to put SQL statement directly in combobox RowSource instead of basing combobox RowSource on a dynamic parameterized query object - then it will work whether form is standalone or a subform.
SELECT Answer FROM InterviewAnswers WHERE QuestionID = [txtQuestionID] ORDER BY Answer;

Re: Delete selected item from two list boxes

I'm a bit of a newbie and my question probably has a simple answer... I have searched this site and Google, but haven't found an answer yet? JaredPar's answer to the above question seems to be the answer to my current need, but I pasted his code into my program and it gives me the following problem:
SelectedIndex is not a member of ListView.
This is the only code I have found so far to delete the same selected item from more than one ListView.
I am inserting node text from a Treeview into a ListView and a DataGridView(DGV). When the user inserts the wrong item from the Treeview and decides to delete it both from the Listview and the DGV, the user selects the item from the current list in Listview and clicks the Delete button. This should delete the same item in both the Listview and the DGV to maintain both lists updated. The Listview is used for a visual list during user selection of items by clicking on Treeview nodes. The DGV is used for filtering a saved list of all the items introduced by user in this way.
I was using the following code until I came across the code by JaredPar under the above title, but this only removes an item from Listview. JaredPar's code appears to remove the selected item from 2 Listviews:
For i As Integer = ListView1.SelectedItems.Count - 1 To 0 Step -1
ListView1.SelectedItems(i).Remove()
Next
I hope my question is understandable and that someone can help me with this to be able to learn from your examples! Thanks for any help!

Dynamic / Static items in radComboBox. (SQL Query error)

I am using telerik's rad combo boxes (dropdowns) on my aspx page. there are 3 rad combo boxes and they are cascading dropdowns. the items in the final dropdown is dependent on the selection of the 2nd dropdown.
Now, i had to insert a "select all" option in the final dropdown. this being a static value, i added it using "appenddatabounditems" property of the rad combo box, setting it to be true. I can now see the select all option, but the items in the dropdown list are repeated. I have used the distinct keyword in the query. Also, when i make another selection in the 2nd dropdown box, the values in the third dropdown are appended i.e they show "Select all" + items of the previously selected 2nd dropdown option + values of the currently selected dropdown selection.
Am i missing something in the query? or there is something wrong with the telerik controls? or the ajax manager?
PLease help.
Thanks,
ghanshyam.
Are you using the EnableLoadOnDemand="true" setting to perform the cascade? The combo box does not clear the old items out automatically. Two things you can do:
Delete the old items OR
Bind the entire list to the combo box and hide the invalid ones. This has worked for us when the list is relatively small.
HTH.

VB.Net - select whole line in a multicolumn ListView and not only first item

I have a ListView in VB.Net.
I want to use it to display a table of data.
However I want to be able to click on a row and select it.
The component allows me to select a row only by clicking on the first item of each row.
Can I change that?
Is there a better component to display tables? (I've already tried the DataGridView. I don't like it's appearance)
This should simply be a matter of setting FullRowSelect on the control to be True.
Change the FullRowSelect property to True.

Grids get empty when I click on some other tab

I have a question, I have a combo box, which when changed fills the data grid. Now Wen I change the Tab and come back to same tab again(one containing the combo box)..the value of combo box remains there, however the grid gets empty. I need this data to be maintained till the user selects another value from drop down.How can this be done???
Any suggestions would be appreciated.
Some of the possible reasons :
There is a MyDataGrid.clear somewhere
The DataSource used to fill the grid is somewhere cleared.
If you use a DataSet, your DataTable is somewhere truncated.
If you use a BindingSource as your DataSource, maybe somewhere else you're using the same BindingSource, which empties the grid.
I would recommend you to put a braekpoint on your Combobox change value event to see if it's not called with a wrong value somewhere else.
And I would add a spy to check your DataGrid (the number of lines for example) to precisely know where it happens by executing my code step by step.
Hope this helps !