How to designate unique items in a datagridview combobox dropdown list - vb.net

I use the following code to fill comboboxes in a datagridview column. The combobox column is created with the designer.
Code in Form1_Load:
Me.Sec_400TableAdapter.Fill(Me.Test1DataSet.Sec_400)
Me.DataGridView1.DataSource = Me.bindingSource1
GetData("select CulType, PrKey, diam from Sec_400 where RdNo = '33-3-33'")
When I run the code, all the comboboxes in the datagridview column properly display "Aluminized" or "Galvanized" items from the Sec_400 table. However when I click the down arrow to see the two options and pick the other choice, all the "Galvanized" and "Aluminized" items from the rows in the datatable are displayed. I just want one "Galvanized" and one "Aluminized" item to show as dropdown menu items.
I've tried entering Aluminized and Galvanized in the "edit columns" designer under "collection items", but after I key them in they are gone when I return to view them. There must be a way to make the dropdown items only two unique values. But How?

Related

Adding an item to the end of a multi-column listbox

Being a beginner in this, I've tried to search for a solution to my issue. I created a form in Access 2013 with a List Box. The List Box is bounded to a table with 10 fields.
For the List Box, in the Property Sheet, I've set the Column Count to 10, but have hidden some columns, i.e. some has a Column Widths of 0" because I'm only showing important data in the List Box.
The Row Source Type of the List Box is set to Table/Query.
When I open the form, it queries the table and populates the List Box with all data.
I have 4 unbounded Text Box that allows the user to enter data, and have a button to allow the input data to be added to the end of the List Box and also be automatically added to the table.
I've searched for how to do this:
Add items to a multi-column List Box
vba listbox multicolumn add
Adding items in a Listbox with multiple columns
Adding values multiple columns to listbox in form access vba
Excel multi-select, multi-column listboxes
I've tried to use the .List property of the List Box, but it does not exist.
I've tried to do something like:
Me.MyList.AddItem "" & ";" & Me.textBoxValueOne & ";" & Me.testBoxValueTwo & ";" & ""
However, VBA complains I need to change the .RowSourceType to Value List, and when I added it, the List Box clears all the data, and adds this data as the first entry, which is not what I want.
I've added the following code, which adds a blank entry to the end of the List Box as well as table, but I don't know where to go further with it to save the input data from the Text Box to the end of the List Box and table:
DoCmd.GoToRecord , , acNewRec
DoCmd.RunCommand acCmdSaveRecord
Me.MyList.Requery
How can I achieve this?
Thanks.
You need to add the record to the table first and then requery your listbox.
After adding the new record try
Me![column name] = textbox1.value
And other textboxes
Followed by your save command.
Once you've added the record. Simply requery the listbox.
Me.listbox.requery

sql show listbox values only when combobox is populated

Firstly, I'm pretty new to access so I apologise if this is basic but I can't find the right answer either.
I've had some help setting this up so there are parts that have been created that I don't fully comprehend.
I have created a form that is to be used for data entry which consists of the following fields:
TEAMS - Combobox the rowsource of which is a table TEAMS; CALLREASONS - Multi-Select Listbox the records of which currently exist in a table CALLREASONS; ACTIONS - Multi-Select Listbox the records of which currently exist in a table CALLACTIONS; SUBMIT - Button with VBA which sends selected data to a number of tables.
The database works fine and things a saving where they should be and in the format they should be, the problem I'm having is with the display of the form.
I would like for the form to display blank when opened and after each time a record is submitted. However, if I set the rowsource of the listboxes to the tables all options show when the form is loaded and after each submission the options and the previous selections show.
How can I make it so that the first listbox CALLREASONS only displays possible options once a selection has been made in the combobox TEAMS and the second listbox CALLACTIONS only displays possible options once at least one selection is made in the listbox CALLREASONS ?
Thanks in advance for any help.
You can either change the controls row sources on the Update or Enter events, or you can simply enable/disable them on the events.
Lets use 3 nested comboboxes for an example.
Combo1 Has rowsource set permanently as it is the top level.
Combo2 and Combo3 Have no rowsource set.
On the Enter event of Combo2, you can set the rowsource to
SELECT Pkey, DisplayText FROM tblOptions WHERE OptionGroupField = " & Forms!Form1!Combo1BoundField
On the Enter event of Combo3, you can set the rowsource to
SELECT Pkey, DisplayText FROM tblOptions WHERE OptionGroupField = " & Forms!Form1!Combo2BoundField
So on so forth.

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 / DataGridView / ComboBoxCell?

I am using vb.net 2010 and winforms and DataGridView.
The DataGridView has a DataGridViewComboBox column. When I show the form with the DGV it shows this and empty grid but the column that contains the ComboBox shows the first item on the dropdown list.
How can I have the ComboBox display nothing until it is clicked on and selected?
Try setting the combobox selectedindex property to -1 when you initialize it. That might fix your problem, but when I do the same thing that you described, mine doesn't show any values in the combobox until I click on it. Here are the steps I took:
1. create a datagridview control.
2. right click on control and add column.
3. add DataGridViewComboBoxColumn
4. right click on control and edit columns.
5. Click on the button for "Items (Collection)".
6. Add some items
Now your control should behave how you are asking. It works fine when I run it. If it doesn't it may be a VS2010 bug since I'm running VS2008.
Edit:
When you add your items in code, just set the combobox value to Nothing:
Dim cboBrand As New DataGridViewComboBoxColumn
With cboBrand
.HeaderText = "Brand"
.Name = "Brand"
.Width = 300
.Items.Add("item1")
.Items.Add("item2")
.Items.Add("item3")
End With
Me.DataGridView1.Columns.Insert(0, cboBrand)
DataGridView1.Rows.Insert(0, New Object() {Nothing})
or if you want to set an initial value, do it like this:
DataGridView1.Rows.Insert(0, New Object() {"item2"})

Can I page through grouped data in DataGridView?

I have a simple VB.NET 2008 app that helps users to edit fields in the database. Simple enough as a first "real" project in .NET, right?
For one table, I am currently using a DataGridView so it can be edited straight up. However, instead of offering the user the entire table, I'd like to group the data by the 'CompanyNumber' column and use a navigator to page through. In other words, I'd like the DataGridView to show me all the lines related to one company, then click the "next" arrow to show the next company, etc.
(I know I could do this with Xceed DataGrid, but I'm using Windows Forms not WPF, and I'd really prefer to do this with "pure" ADO.NET for this project.)
Update 2009-09-28:
So I have created a ComboBox filled from the same BindingSource, and configured its SelectedIndexChanged to change the Filter value on the DataGridView.
But still, filling the ComboBox--which should be easy!--continues to be a problem. I can either:
(a) fill it from the BindingSource, in which case I see multiples of each 'CompanyNumber' and I can't figure out a way to show only distinct values, or
(b) create another TableAdapter in the data source which is just a "Select DISTINCT CompanyNumber..." query, which mostly works, except that that first value of the list changes when I change the selection (e.g. if the ComboBox shows "100, 101, 102, 103" and I pick "102", then the list will show as "102, 101, 102, 103").
Any recommendations?
(Also, bonus if you can suggest how to make the BindingNavigator's arrows page through the 'CompanyNumber' filters instead of the items in the DataGridView... which is what I'd really like to see.)
What you could do is just force the DataGridView to sort CompanyName, this way all rows with the same company name are next to each other and the user can navigate the data grids with the paging that comes with it.
Alternatly, you could follow through with your combobox/DropDownList idea, which would be best. From what I understand when you select an item in the combobox everything in it changes?
Another way is to create two separate buttons, "Previous" "Next", that when clicked, will change the DataGridView's binding source to only show a certain company. You would need to store an array of company names, then store what the current DataGridView's binding source is displaying.
I ended up figuring it out myself, and the solution is clean and simple. Here are the basic steps:
create a DataView off of the table out of the DataSet
use the DataView.ToTable() method to create a new table filtered to only distinct values from the needed column ('CompanyNumber')
create a BindingSource which uses the new DataTable as its DataSource
bind the ComboBox to the new BindingSource
bind the BindingNavigator to the new BindingSource
Because the ComboBox and the BindingNavigator use the same BindingSource, they will update each other with the changes automagically.
Here's the rough code:
Private Sub CoNumsComboxBox_LoadData()
Dim dvCoNums As DataView, dtCoNums As DataTable
dvCoNums = New DataView(Me.ODBCDataSet.Tables("CompanyFundProfile"))
dvCoNums.Sort = "CompanyNumber ASC, FundNumber ASC"
dtCoNums = dvCoNums.ToTable("CompanyFundProfile", True, "CompanyNumber")
CoNums_BindingSource.DataSource = dtCoNums
CoNumsComboBox.DataSource = CoNums_BindingSource
CoNumsComboBox.DisplayMember = "CompanyNumber"
CoNumsComboBox.ValueMember = "CompanyNumber"
'attach handler which changes DataGridView1's filter when this changes
AddHandler ToolStripComboBox1.SelectedIndexChanged, AddressOf CoNumsComboBox_SelectedIndexChanged
CompanyFundProfile_BindingNavigator.BindingSource = CoNums_BindingSource
End Sub