combobox default value, vb.net - vb.net

i have a combobox that populates from a database column but when the form loads, the combobox appears with the first item on the database. the value of this particular combobox determines the value of some other controls on the form so i want the combobox to load with an empty entry. thanks as i'll appreciate any help i can get.
here is my code:
'all variables declared...
connection.Open()
command = New MySqlCommand("SELECT PUMP FROM test.pump", connection)
dataadapter.SelectCommand = command
dataadapter.Fill(dataset)
With Me.PumpComboBox
.DisplayMember = "pump"
.DataSource = dataset
End With

Use
combobox1.SelectedIndex = -1
This sets the value of the combo box to a blank entry.

Maybe adding empty value and then selected that empty value using selectedindex after the combbobox populated will work

In your Form.Load include the following:
ComboBox1.SelectedIndex = 1
Here "ComboBox1" is your ComboBox and "1" equals index you want to be set by default.

Related

vb.net Filling data-set value as combo-box value-member issue

myORAConnection.Open()
Dim SQLString As String = "Select child_id as id, child_name as name from xxi_org_structure_v Where parent_id=" & LegalEntity & ""
Dim cmd As New OracleCommand(SQLString, myORAConnection, OraTrans)
Dim daTableORA As New OracleDataAdapter(cmd)
daTableORA.Fill(dtOrg)
daTableORA.Dispose()
cmd.Dispose()
myORAConnection.Close()
With IT_ORG_CODEComboBox
.DataSource = dtOrg.Tables(0)
.ValueMember = "id"
.DisplayMember = "name"
End With
Catch ex As Exception
MsgBox(ex.Message)
End Try
'TODO: This line of code loads data into the 'Main_POSDataSet.pos_promotion_item_group_details' table. You can move, or remove it, as needed.
Me.Pos_promotion_item_group_detailsTableAdapter.Fill(Me.Main_POSDataSet.pos_promotion_item_group_details)
'TODO: This line of code loads data into the 'Main_POSDataSet.pos_promotion_item_group_headers' table. You can move, or remove it, as needed.
Me.Pos_promotion_item_group_headersTableAdapter.Fill(Me.Main_POSDataSet.pos_promotion_item_group_headers)
I am filling the combobox with value from oracle, but getting the selected value from sql and storing it to sql too.
I am getting the value to fill in the form from "Main_POSDataSet.pos_promotion_item_group_headers", however I want to tell the form or the dataset or the combobox that the value retrieved from the "IT_ORG_CODE" column is to be used as combobox value-member and not display member.
is there anyway to solve this please ?
237 is the organisation id to use as combobox valuemember, but here it is used as display member !!
Just replace
Me.IT_ORG_CODEComboBox.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.Pos_promotion_item_group_headersBindingSource, "IT_ORG_CODE", True))
With
Me.IT_ORG_CODEComboBox.DataBindings.Add(New System.Windows.Forms.Binding("SelectedValue", Me.Pos_promotion_item_group_headersBindingSource, "IT_ORG_CODE", True))
in the form designer code

Having trouble getting data to show correctly in ComboBox

dbConn.Open()
Dim Query1 As String = cmbManufacturer.Text
Dim AccessDataAdapter = New System.Data.OleDb.OleDbDataAdapter
AccessDataAdapter.SelectCommand = New System.Data.OleDb.OleDbCommand("Select Models.[ModelName] From Models Where Manufacturer = '" & Query1 & "'", dbConn)
Dim AccessDataset = New DataSet
AccessDataAdapter.Fill(AccessDataset, "Query1")
cmbModel.DataSource = AccessDataset.Tables("Query1")
dbConn.Close()
So what this does is, it takes the selection from the manufacturer combo-box and determines the values that will display in the model combo-box
I've seen similar questions like this, but mostly in c# so I'm having trouble relating them. The problem is the output on the desired combo-box is
System.Data.DataRowView
when I need it to be the model names that it's pulling from the query. I changed this from a set of static entries in each combo box to make them dynamic, so in the future we wouldn't need to change the code to add or remove devices from the program.
When .DataSource is using for filling ComboBox with items, then DisplayMember used to retrieve a dipslayed text from the bounded object
From MSDN:
If the specified property does not exist on the object or the value of
DisplayMember is an empty string (""), the results of the object's
ToString method are displayed instead.
You are not used DisplayMember property, so method ToString() was called on the object, which is System.Data.DataRowView
You need to set a column name which you want use as displayed text
cmbModel.DisplayMember= "ModelName"
'If you will use a SelectedValue for furthers purposes
'Then you maybe want to set a ValueMember too
cmbModel.ValueMember= "ModelName"
cmbModel.DataSource = AccessDataset.Tables("Query1")
DisplayMember Property

how to retrieve the value as array from a dynamically created textbox using its ID in vb.net?

I am new to this programming method. The case is I have created the checkbox and textbox dynamically where the name of the text box and check box is equal and it is handled using database.
The data I need to get is from the textbox which is selected using checkbox by the user.
The details in the array need to be name of the textbox and the value of the textbox
I created the checkbox and textbox using this method. Some thing like this
Dim checkBox = new CheckBox()
Form1.Controls.Add(checkBox)
checkBox.Location = New Point(offset, 10)
checkBox.Text = cur
checkBox.Checked = True
checkBox.Size = New Size(100, 20)
I successfully created checkbox at run time. Help me getting the value, and suggest me with the suitable array list.
the naming for the check box is number 1 to n values same for the textbox

Combobox Make First Row As Display

So my combobox is used to populate a datagridview when user clicks the customersID in the combobox it will popupate the grid. I have the code for populating but the problem is that they combobox does no reset itself. It still shows the current value that was Selected. I wanted to know it is posible to reset the combobox after selected index event. The code below is how i got my combobobox.
' after a command and connection was made
customerAdapt = New SqlDataAdapter(customerQuery,con)
customerSet = New DataSet
customerAdapt.Fill(customerSet)
customerCb.DataSource = adoAddtRs.tables(0)
customerCb.DisplayMember = "custID"
customerCb.ValueMember = "custID"
customerCb.Visible = False
customerCb.DropDownStyle = ComboBoxStyle.DropDownList
Try this piece of coding
customerCb.selectedindex = -1

combobox with first row blank

I have a a ComboBox bound to a DataSet. I would like to have combobox with very first row blank. How can I do this?
I've tried following
With .RoomComboBox
.DataSource = Me.aRoomsBindingSourse
.DisplayMember = "Room"
.ValueMember = "BedCode"
.DataBindings.Add("text", aRoomsBindingSourse, "Room", False,DataSourceUpdateMode.Never)
.SelectedIndex = -1
End With
Thank you in advance.
I don't think you can do this. Because .net framework doesn't allow to modify items if the DataSource set.
Hook into the post data bind event and add a row at the first location.