change the list of combobox A based on the item chosen from combobox B - vb.net

I am new to vb.net and I am using visual studio 2010. I have two comboboxes on a form, each combobox is set to DropDownList so that a list of items can show in the combobox, but no text is allowed to be entered.
For combobox A, if user chooses item 1, the list of combobox B should be updated accordingly. I think this is quite common on a lot of applications. But I do not know to implement it. I even do not know the keyword to search for the relevant property or event handler.
Thanks a lot!

Take a look at SelectedValueChanged. You can subscrive to this event on your first combobox, then when the event is raised, you can combo2.Items.Clear () the 2nd collection, then add your items.

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;

When binding both the Items and SelectedValue to aListBox I seem to get a race condition, how to fix?

For a legacy project, I have a WinForm with a BindingSource1 bound to a strongly typed SQL 2005 DataSet. There is a BindingSource2 bound to the first on a relation.
When selecting a Row in DataGridView, I'd like to present a ListBox with all the child rows with one Item selected based on a value in the selected Row. I bound the DataGridView to BindingSource1, the ListBox' Datasource is BindingSource2, ValueMember and DisplayMember are set to the primary key and a description respectively. I added a Databinding of SelectedValue to the foreign key in BindingSource2.
On Load of the Winform and when the selected row changes by changing the sort order, everything is fine, all related rows show up in the ListBox and the correct item is highlighted.
When I click into the DataGridView, .Net seems to change the SelectedValue of the ListBox and repopulate its items after that. In Effect, when the newly selected item is already in the ListBox it gets highlighted, then the ListBox is filled with the new items and the first one is selected (SelectedValue is reset).
Is there any .EndEdit, .CancelSomething or .UpdateFoo that I am missing? How to ensure the internal sequence of Items.Clear(), (fill), and SelectedValue = x? I am stripping down the problem to a minimal project but if anyone has an idea I'd like to skip that part ; )
Added: All Bindings are set using the Designer of Visual Studio 2008 Pro, the project is VB.Net Framework 2.0 Winform.
I am documenting my workaround to further describe the problem I have. It might help others and possibly lead to a real solution.
Like in "How to bind the "SelectedValue" property of a combobox that gets his elements from a datasource?" the control is filled by DataSource, DisplayMember and ValueMember plus has a DataBinding of its SelectedValue. There seems to be a problem: In ListBox and ComboBox the Position of the DataSource (BindingSource2 in my example) define the current selected Item, binding SelectedValue to another DataSource leads to erratic behaviour.
For my workaoround I bound ListBox.DataSource to a DataView wich is filled / filtered in BindingSource2_ListChanged so the DataSource of the ListBox has no Position to use as SelectedItem / Index / Value. It then uses the DataBinding only and my UI shows the expected Behaviour.

MS Access: listbox appears to be locked when assigned to ID's on continous form

I have a continuous form where i have a listbox assigned to an ID. I cant seem to select anything in the list box. I have the row source property set to a Value List. I manually typed in "Y";"N" for the list.
If I don't assign the control source to the ID, all listboxes are selected at once on the form.
Is there any property I should change?
Thanks
You cannot sensibly use unbound controls on a continuous form.

How to make custom Combo box control which have contain datagrid in vb.net

I want to make custom combo box which have contain datagrid and textbox too.
On clicks into combo box datagridview should be appear and selecting any row particular cell value of the datagridview added on the combo.
thanks in advance..
As your question is written I have no idea how to answer it, I can't figure out how you could sensibly show a DataGridView inside a ComboBox. I'm writing this answer with the assumption that you mean that the form should have a ComboBox that are "linked" to a DataGridView rather than actually contain it.
If so, all you need to do is to add the ComboBox and DataGridView to the form, make the DataGridView invisible. Then you handle the SelectedIndexChanged event for the ComboBox, in the handler, make the grid visibile, find the index of the row and column you want to show and write code like (code not tested so might not be correct):
grid.SelectedRows.Clear()
grid.FirstDisplayedScrollingRowIndex = rowIndex
grid.Rows(rowIndex).Cells(colIndex).Selected = True
grid.Show()

Changing styling of DataGridViewComboBoxCell from DropDownList to DropDown?

(This question is narrower in scope than this question I asked earlier.)
Say I have a DataGridViewComboBoxColumn, and want to switch the style of the ComboBox control between DropDownList and DropDown (mainly for the text field editing capability). I'd like to do this on a row-by-row basis (at the DataGridViewComboBoxCell level).
How would I do that programatically?
Or maybe a different way of asking: How do I access the ComboBox control given an object of type DataGridViewComboBoxCell?
(I'm in VB 2005.)
Thanks as always.
Not sure if you still need an answer, but i have a question that covers similar ground: Detect which column is showing an editing control in a datagridview
i use something like this line to get the combobox out of the DataGridView (DGV) in my DataGridView's CellValidating event:
Dim comboBox As DataGridViewComboBoxCell = DGV.Item(e.ColumnIndex, e.RowIndex)
later i use this line to get change the DropDownList ComboBoxCell to a DropDown:
cb.DropDownStyle = ComboBoxStyle.DropDown
For mine to work i had to make sure the 'cb' was of the ComboBox type, i dont remember if i was able to get it working well if the combobox was of the DataGridViewComboBoxCell type.