Populating a dropdown menu in Visual Basic 2008 - vb.net

I would like to populate a drop down list using values from the database. I would like to know how I can add to the dropdown list both the display member and value member straight all from the database
Display Name: Account_Name
Member Value: Account_ID
Is this possible? If yes, How is it done

Assuming you are binding programatically using a datatable/datareader or similar. Use the DataTextField and DataValueField Properties. e.g.
DropDownList.DataValueField = "Account_ID"
DropDownList.DataTextField = "Account_Name"
EDIT
For a combo box with a datareader you would use something akin to the following
YourComboBox.DataSource = yourDataReader
YourComboBox.ValueMember = "Account_ID"
YourComboBox.DisplayMember = "Account_Name"

Related

How to use a combobox in ms Access to display the value of field in table and at the same time present the users with a list of options to edit?

I have an unbound form where my controls (among which there are some comboxes) are filled with data in a DAO.Recordset rst (opened with a SELECT SQL statement):
me.Controls("mycontrol").Value = rst.Fields("somefield")
The combobox displays the correct value ('YES' or 'NO') stored in the table. How can I make the combobox display these two options to the user if he wants to change the value? And how to I get the value the user picked (in VBA)?
Never mind. I think I did it!
mycontrol.RowSourceType = "Value List"
mycontrol.RowSource = "YES;NO"

VB.net (Dev Express XtraReport)

Developing a VB.net Winform project with Dev ExpresDataSSols. After declaringan open SQL connection, SQL command /SqlGridAdapter, I assigned a DataTable to a Grid Control tool. The GridView from my Grid Control was passed to a Dev Express XtraReport object. The XtraReport successfully showed the DataTable from the GridControl's GridView. - I then attempted to add a Dev Express CalculatedField to my XtraReport, but the CalculatedField is not displayed in the XtraReport. Any ideas on how to correct this code? Thanks!
Dim rep As XtraReport = New XtraReport( )
rep = ReportGenerator.GenerateReport(rep, GridView1)
Dim calcField As New CalculatedField( )
rep.CalculatedFields.Add(calcField)
calcField.Data Source=rep.DataSource
calcField.DataMember=rep.DataMember
calcField.FieldType=FieldType.Int32
calcField.Name="Total"
calcField.Expression="SUM([Field])"
rep.ShowPreview()
Can you confirm that the field that you want to sum is named Field?
Are you sure to have value in the database for that field?
based on the documentation it seem ok.
sorry i can't comment because i'haven't enought reputation..
I see that you've added a calculated field to a report, but have not created a label or table cell that's bound to the calculated field. This is demonstrated in the Creating a Calculated Field (Runtime Sample) topic:
/ Bind a label's Text property to the calculated field
// depending on the report's data binding mode.
if (Settings.Default.UserDesignerOptions.DataBindingMode == DataBindingMode.Bindings)
report.FindControl("xrlabel3", true).DataBindings.Add("Text", null, "Products.myField", "{0:c2}");
else report.FindControl("xrlabel3", true).ExpressionBindings.Add(
new ExpressionBinding("BeforePrint", "Text", "FormatString('{0:c2}', [myField])"));

How to use the value not displayed by a dropdown when connected to access database

My program uses a database in access which consists of BreedID and BreedName. I have a dropdown box in vb.net which shows the name for the user to select, however in my code I would like to store the ID related to that name so that I can send it over to the access database using oledb. Currently this is what it looks like:
Dim BrVar As String = Breed.SelectedItem.Text
But that isn't working! Please help!
You can add hidden columns to your dropdown box, it may already exist. The first column in a dropdown box is column(0) and you can set the width to 0cm. This can be for the ID value. Leaving column(1) for the Name value.
Then you can use Breed.SelectedItem.column(0)
The first thing to do is on the Data tab set up your rowsource to SELECT both the BreedID and BreedName fields (in that order). Then make sure bound column is set to 1.
Then on the Format tab set Column Count to 2 and Column Widths to 0;1.
That will have the result of displaying the BreedName field but using the BreedID field as the value of the combo box.
Use Dim BrVar As Long = Breed.SelectedItem to get the value of BreedID.

Xpages Getting Dojo Combo Box to have drop down

I am writing an Xpage in which the user can create a new document. On field is a category field. I want this field to be a drop down or type ahead with the possible values to be based upon previous entries. The user should also be able to add a new entry.
So this is the equivalent to a traditional dialog list field with "formula for choices" and the formula comes form the first categorized field on a view, with the "Allow values not in list" checked.
I am using a dojo Combo Box, but it displays the values in the field itself, instead of in a drop down.
Not sure what I am doing wrong:
My code is
<xe:djComboBox id="djComboBox2"
style="width:400px">
<xe:this.value><![CDATA[${javascript:var tmpView:String = "tipsByCategory";
var tmpColumn = 1;
var tmpVals = #DbColumn("",tmpView,tmpColumn);
tmpVals}]]></xe:this.value>
</xe:djComboBox>
In djComboBox
property value does the data binding to a document's field or a
scope variable
property selectItems has to deliver the list of possible entries
user can choose from.
Your code should look like this then:
<xe:djComboBox
id="djComboBox2"
style="width:400px"
value="#{document1.yourField}">
<xp:selectItems>
<xe:this.value><![CDATA[${javascript:
var tmpView:String = "tipsByCategory";
var tmpColumn = 1;
var tmpVals = #DbColumn("",tmpView,tmpColumn);
tmpVals}]]></xe:this.value>
</xp:selectItems>
</xe:djComboBox>

HOw to use SelectedValuePath to get the ID

I want to Get the Database ID of the item selectd in the Combo box in silverlight either by using SelectedValuePath or by any other way.
Please suggest.
In XAML you must to write de name your Id in the combobox:
SelectedValuePath="ID"
where "ID" is the name of your field.
To get the selected value in c#:
int id=(int)myComboBox.SelectedValue;