Retrieving both values from a 2 column ComboBox VBA - 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)

Related

MS Access ComboBox Storing the Wrong Bound Column Value

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.

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.

How to have values from 3 columns shown in combobox VBA (active x control)

In combobox I set columnCount to 3, so when I click dropdown arrow I can see 3 columns that I need, but when I choose one row that I need, there is only value from first column shown. Combobox is wide enough for all three columns. Is there a way to see all 3 when I select my choice?
You need to change the ListFillRange to all the columns in your list:
Sheet1!$A$5:C20
Also you need to have a single cell referenced in the LinkedCell property: Sheet1!$A$1
The bound column must be a value between 1 and 3. You can only return a single value from the list - this will be from the bound column.
Your column count must be 3.
Your column widths must be either blank or a value >0 (0 will hide the column):
85.05 pt;85.05 pt;85.05 pt
With those in place you should be seeing three columns of values in the list box - you can only return a value from one of those columns though.
If you want to return more than one I'd suggest using a hidden (column width of 0) column to contain a unique identifier and then use a look-up on the sheet to fill in the blank columns.
To get to all three columns in VBA use code similar to:
Private Sub ComboBox1_Change()
With Me.ComboBox1
MsgBox .Column(0) & vbCr & .Column(1) & vbCr & .Column(2)
End With
End Sub

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