Home > Net >  Read from the database and update the DataTable, led to the use of the table as a data source ComboB
Read from the database and update the DataTable, led to the use of the table as a data source ComboB

Time:09-15

Dim DataSet1 As New DataSet 'build table such As slightly

Dim ComboBox1 As New ComboBox
ComboBox1. DropDownStyle=ComboBoxStyle. DropDown can
ComboBox1. AutoCompleteSource=AutoCompleteSource. ListItems
ComboBox1. AutoCompleteMode=AutoCompleteMode. Suggest

'the combo box data
Dim DataTable1 As DataTable=DataSet1. Tables (table "goods")
Dim DataView1 As New DataView
DataView1. Table=DataTable1
ComboBox1. The DataSource=DataView1
ComboBox1. DisplayMember="name"
ComboBox1. ValueMember="encoding"

'binding
Dim DataTable2 As DataTable=DataSet1. Tables (" business table ")
Dim DataView2 As New DataView
DataView2. Table=DataTable2
Dim BindingSource2 As New holding
BindingSource2. The DataSource=DataView2
ComboBox1. DataBindings. Add (" SelectedValue BindingSource2, "code", True, DataSourceUpdateMode. OnPropertyChanged)

'the form operation
ComboBox1. Text=""
ComboBox1. SelectedIndex=1

Dim Cnn1 As the New System. The Data. The OleDb. OleDbConnection 'connection slightly
Dim OleDbDataAdapter1 As the New System. The Data. The OleDb. OleDbDataAdapter
OleDbDataAdapter1. SelectCommand=New System. The Data. The OleDb. OleDbCommand
OleDbDataAdapter1. SelectCommand. Connection=Cnn1
OleDbDataAdapter1.SelectCommand.Com mandType=CommandType. Text
OleDbDataAdapter1.SelectCommand.Com mandText="Select goods table. * From the commodity list"
OleDbDataAdapter1. The Fill (DataSet1, "commodity table") 'RowChanged incident, still normal
'here, ComboBox1 automatically choose the drop-down list of the first


The above procedures section is to write up, is not a complete code, don't need to care, the main problem is that from the database to read in the data table of the combo box, why will lead to the combo box automatically choose?
As the data source table is public data table of multiple forms combo box, never use RaiseListChangedEvents=False this kind of treatment method, why not, and the solution, please use VB.Net to solve, thank you very much!





CodePudding user response:

Save option sequence next time use, binding post-processing,

CodePudding user response:

What I want is the combo box null values, does not need to save any options sequence, and is bound,

CodePudding user response:

Option Explicit On
Public Class ClassDataGridView1
Inherits the Form
'the test form

Private Button2 As Button, ComboBox2 As ComboBox, BindingSource2 As holding

Sub New ()
ComboBox2=New ComboBox
ComboBox2. DropDownStyle=ComboBoxStyle. DropDown can
ComboBox2. AutoCompleteSource=AutoCompleteSource. ListItems
ComboBox2. AutoCompleteMode=AutoCompleteMode. Suggest

'the combo box data
Dim DataTable1 As DataTable=DataSetVS. Tables (" Goods ") 'to build a database table, As long As there are these two columns: GdGoodsSerial, GdGoodsName
Dim DataView1 As New DataView
DataView1. Table=DataTable1
ComboBox2. The DataSource=DataView1
ComboBox2. DisplayMember="GdGoodsName"
ComboBox2. ValueMember="GdGoodsSerial"

'binding
Dim DataTable2 As DataTable=DataSetVS. Tables (" BOMStruct ") 'to create a database table, As long As there is a column: BSGoodsNum
Dim DataView2 As New DataView
DataView2. Table=DataTable2
BindingSource2=New holding
BindingSource2. The DataSource=DataView2
ComboBox2. DataBindings. Add (" SelectedValue BindingSource2, "BSGoodsNum", True, DataSourceUpdateMode. OnPropertyChanged)

Button2=New Button
AddHandler Button2. Click AddressOf Button2Click

, AddressOf AddHandler Me. To Me. Shown1
End Sub

Private we disposed As Boolean=False
Protected Overrides Sub Dispose (disposing As Boolean)
If Not Me. The disposed Then
If disposing=True Then
Button2. The Dispose ()
ComboBox2. The Dispose ()
End the If
End the If

Me. Disposed=True
MyBase. The Dispose (disposing)
End Sub

Protected Overrides Sub Finalize ()
Me. The Dispose (False)
End Sub

Private Sub Shown1 (FormN As the Form, As EventArgs e)
Me. FormBorderStyle=FormBorderStyle. SizableToolWindow
Me. WindowState=FormWindowState. Maximized

Button2. Size=New Size (100, 25)
Button2. Location=New Point (0, 100
Me. Controls. The Add (Button2)

ComboBox2. Size=New Size (200, 25)
ComboBox2. Location=New Point (0, 200
Me. Controls. The Add (ComboBox2)
End Sub

Private Sub Button2Click (sender As Object, e the As System. EventArgs)
ComboBox2. Text=""
ComboBox2. SelectedIndex=1

Dim Cnn1=New System. The Data. The OleDb. OleDbConnection 'create connections can

Dim OleDbDataAdapter1 As the New System. The Data. The OleDb. OleDbDataAdapter
OleDbDataAdapter1. SelectCommand=New System. The Data. The OleDb. OleDbCommand
OleDbDataAdapter1. SelectCommand. Connection=Cnn1
OleDbDataAdapter1.SelectCommand.Com mandType=CommandType. Text
OleDbDataAdapter1.SelectCommand.Com mandText="Select Goods. * From Goods", "
OleDbDataAdapter1. The Fill (DataSetVS, "Goods")

'here, ComboBox1 automatically choose the drop-down list of the first

End Sub

The End of the Class

CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related