MS Access ComboBox Storing the Wrong Bound Column Value - vba

I have a ComboBox object in an Access form that pulls its data from a query. The Query returns 2 columns. For example, the columns are "Section" and "Title". "Title" is the value I would like stored and displayed in the ComboBox once selected, but "Section" is the value that displays, regardless of the Bound Column value I set.
Both columns are necessary information in the drop-down list (for user context), but only "Title" is required by the Access Form, as it is the primary key in its own table, and "Section" is not a unique value from which "Title" can be logically derived.
The display order of the columns in the dropdown is "Section | Title" and shall remain so, since it will read "1.1.2.1 | Introduction to History" in the list which is more legible than the inverse.
As mentioned, I've tried setting the Bound Column value to 0, 1, 2, and 3, knowing that there are only 2 columns to choose from and that Bound Column starts at an index of 1.
Bound Column: 0 - Returns Blank (Out of Range)
Bound Column: 1 - Returns Column 1 ("Section")
Bound Column: 2 - Returns Column 1 ("Section")
Bound Column: 3 - Returns Blank (Out of Range)
Both columns display on the dropdown list, but any reasonable change to the Bound Column property does not stop the ComboBox from displaying the first column from the selected row every time. Having the query return an extra third row and setting the Bound Column to 3 also does not change the outcome -- "Section" is still the displayed value.

Related

DataGridViewComboboxCell display member not showing up

Goal
A datagridview of SteelTypes has a column that has been bound to a dataview (SteelThicknesses). I can select the data and set it correctly. However I cannot load the same information. My datagridview comboboxcell contains the value and editted formatted text but I cannot set the display member information.
Current problem
I have all of my textbox columns loading correctly except the combobox column. The variable of cbCol is set correctly and the EditedFormattedValue and FormattedValue contain the value I want! However the displayMember does not get replicated into the datagridviewcombobox cell.
I am trying to display a "3" into the Épaisseur (thickness) column via setting its value to a primary key (PK_SteelThickness):
See the results below. Everything except my comboboxcell is populated:
Appreciate the help in advance, this has gotten me crazy :)
You don't set the text. You set the underlying ID. The idea is that you bind the column to a parent table and you bind the grid to a child table that has a foreign key to that parent table. You set the foreign key value in the grid cell and the corresponding text value from the parent table gets displayed.
As an example, let's say that you have a Handedness table like so:
Id Name
1 Right
2 Left
3 Ambidextrous
and you have a Person table like so:
Id Name HandednessId
1 Peter 2
2 Paul 1
3 Mary 3
In your grid you would create a DataGridViewComboBoxColumn and set its DataPropertyName property to "HandednessId". When you then bound your Person table to the grid, the HandednessId column would bind to the combo box column. You would bind your Handedness table to the column and set the DisplayMember and ValueMember to "Name" and "Id" respectively. The grid would then display "Left", "Right" and "Ambidextrous" for "Peter", "Paul" and "Mary" respectively. If you wanted to make Peter ambidextrous, you would set the HandednessId cell Value to 3 and then it would display "Ambidextrous".
See this for more information:
Adding a ComboBox Column to a DataGridView
It seems like you're making a lot of work for yourself here. Datagridcombobox can be used to decode a value simply by having its
DataSource set to something that provides the key/value lookup, for example a SteelThicknesses datatable with two columns Disp and Val and has rows like "Thick",1 "Medium", 2 "Thin", 3,
DisplayMember set to a string of the column name from the lookup table that contains the text to show, for example "Disp",
ValueMember set to the string column name from the lookup that has the value that relates to the text to show, for example "Val" and
DataPropertyName set to the name of the property(column) in the other table that has the value to be decoded (one of the values in the Val column of the lookup table) (for example a Products table with a SteelThicknessID column).
The datagridview is bound to the products datatable, the combo will find e.g. 3 in the steelthicknessid column, it will look 3 up in the Val column of the steelthicknesses table and show the text it finds in the Disp column of that row from steelthickesses.if the user changes the value shown by dropping the combo list and picking Thick, it will work the reverse and take 1 from the Val column and update the products table with the new value 1 for steelthicknessid. If you don't want that, make the column or datagridview read only
For a more involved discussion see my answer in DataGridView Loading From LINQ
This is an odd behavior but I found that changing my loading method calls from the new() to the form Load() made it work...
So I changed my initial code from this:
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
LoadSteelPlates()
LoadPlateQuotes()
End Sub
To this:
Private Sub frmQuotePads_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LoadSteelPlates()
LoadPlateQuotes()
End Sub
This is the only code that was modified and now it works.

i can't fill my gridview vb.net

In my project , i have 2 windows forms and 1 gridview contains 5 columns (name gridv)
I want to fill 4 columns from forms1 and the 5th columun from the forms2
but i can't do it (error in my appli execution )
my code (how to fill the 5th column)
Dim selectrow As Integer = Form1.gridv.CurrentRow.Index ' selectrow mean selected row indice
MessageBox.Show("ligne selectionnée : " & Convert.ToDouble(selectrow))
Form1.gridv.Rows.Add(corp_mail.Text = Form1.gridv.Item(4, selectrow).Value) ' fill the 5th column`
You haven't shown the error but from what information you have given this is what your code is doing:
evaluates if corp_mail.Text is equal to the value of the 5th column of the selected row. This is a true or false, not a string.
Adds (or tries to) a new row to the grid with true or false as the value of the first cell.
If I understand correctly, this is what you want to do:
Form1.gridv.Item(4, selectrow).Value = corp_mail.Text
This will set the value of the 5th column of the selected row.
Although you mention a second grid on another form, not a textbox, so you probably have more work to do. But the idea is the same, instead of the TextBox value get the value from the other grid.

Retrieving both values from a 2 column ComboBox VBA

I have a user form (excel, VBA) where there is a 2 column combobox. When user selects a certain value from the combobox, I want to get the value he selected, and the value associated with the first value (ie. the second column value).
How do I do this? Simply ComboBox1.Value returns the value of the first column. ComboBox1.Value(0) doesn't work.
Use the column property of the combobox. It is 0-based so the first column is column(0) and the second column is column(1).
Me.ComboBox1.Column(1)

table get the cell from the row

I have one table with 3 rows and 3 columns. Now I want to add 2 row's 2nd columns cell's control. That means whether that is text or combox in the cell. How do I get the 2nd row's 2nd column and remove the compoenent dynamically in SWT JFace?
Do you use a TableViewer?
The SWT-way of getting to the item is indexed first by row, than by column.
Getting the text of the third column in the second row is done like this:
table.getItem(1).getText(2);
To display custom-controls, like a combobox you will have to either paint it manually or use SWT's TableEditor.
Also check out this tutorial: http://www.eclipse.org/articles/Article-Table-viewer/table_viewer.html

Multi-Column ComboBox in Excel VB

I have some ComboBoxes in a UserForm. One of the ComboBoxes is a multicolumn ComboBox with three columns and is dependent on another ComboBoxs' value.
Does anyone know WHY when I choose one of the lines in the multicolumn combobox shows only the first column value?
I want the value from the second column to be visible when I choose a line.
The Combox Property that set which column to display in the TextBox portion of the Combobox is TextColumn
Property values:
-1 = Display the first column whose width (set by ColumnWidths property) is > 0
0 = Display the value of ListIndex
1 = Display column 1
etc