2

これは私を夢中にさせています。メニュー画面のbutton_clickからフォームを呼び出しています。Form2 の form_load の途中で、メニュー画面から button_click を再呼び出しし、form_load を完了していません。2 番目のコンボボックスの execute_reader で常に発生します。

2番目のコンボボックスのコード全体をコメントアウトしようとしましたが、form_loadが完了しましたが、そのフォームを閉じてメニュー画面のボタンをもう一度クリックすると、同じbutton_clickが再呼び出しされますが、adapter.Fill(テーブル)。

frmMenu からのコード

Private Sub btnManageEquipment_Click(sender As Object, e As EventArgs) Handles_ btnManageEquipment.Click
    frmManageEquipment2.Show()
    Me.Hide()
End Sub

frmManageEquipment2_Load からのコード

    Private Sub frmManageEquipment2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    strString = "Select * from equipment"
    adapter = New MySqlDataAdapter(strString, conn)
    Dim commandBuilder As New MySqlCommandBuilder(adapter)
    table.Locale = System.Globalization.CultureInfo.InvariantCulture
    adapter.Fill(table)
    bindEquipment.DataSource = table
    navEquipment.BindingSource = bindEquipment


    Me.txtEqName.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_Name", True))
    Me.cboArea.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_area", True))
    Me.cboEqSubarea.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_subarea", True))
    'Me.cboEqType.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_type", True))
    'Me.txtMarca.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_marca", True))
    'Me.txtModel.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_model", True))
    'Me.txtCapacity.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_capacity", True))
    'Me.txtSerieEquipe.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_SerieEquipe", True))
    'Me.txtSerieMotor.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_SerieMotor", True))
    'Me.txtEngineMarca.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_EngineMarka", True))
    'Me.txtEngineModel.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_EngineModel", True))
    'Me.txtAirFilter.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_AirFilter", True))
    'Me.txtTorqueConversion.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_TorqueConversion", True))
    'Me.txtTransmission.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_Transmission", True))
    'Me.txtAxle.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_Axle", True))
    'Me.txtBrakes.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_Brakes", True))
    'Me.txtStarterElecSystem.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_StarterElectSystem", True))
    'Me.txtTireSize.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_TireSize", True))
    'Me.txtFireSupprSystem.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_FireSupprSystem", True))
    'Me.txtCost.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_cost", True))
    'Me.txtPurchaseDate.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_PurchaseDate", True))
    'Me.txtLifeExpectance.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_LifeExpectancy", True))
    'Me.txtSellPrice.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_SellPrice", True))
    'Me.dtpSellDate.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_SellDate", True))
    ''Me.txtEqID.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_ID", True))
    'Me.txtEqID.DataBindings.Add(New Binding("Text", Me.bindEquipment, "Eq_ID", True))

    cboArea.AutoCompleteMode = AutoCompleteMode.Append
    strSQLArea = "Select distinct(eq_Area) from Equipment order by eq_Area"
    sqlCommand = New MySqlCommand(strSQLArea, conn)
    Dim readerArea As MySqlDataReader = sqlCommand.ExecuteReader()
    While readerArea.Read()
        cboArea.Items.Add(readerArea.GetString(0))
    End While
    cboArea.AutoCompleteMode = AutoCompleteMode.Append
    cboArea.AutoCompleteSource = AutoCompleteSource.ListItems


    cboEqSubarea.AutoCompleteMode = AutoCompleteMode.Append
     strSQLSubArea = "Select distinct(eq_SubArea) from Equipment order by eq_SubArea"
    sqlCommand = New MySqlCommand(strSQLSubArea, conn)
    Dim readerSubArea As MySqlDataReader = sqlCommand.ExecuteReader()
'*****This is where it kicks back to the button click from the menu screen*******
   While readerSubArea.Read()
        cboEqSubarea.Items.Add(readerSubArea.GetString(0))
    End While
    cboEqSubarea.AutoCompleteMode = AutoCompleteMode.Append
    cboEqSubarea.AutoCompleteSource = AutoCompleteSource.ListItems

End Sub

* * *これを処理する方法を完全に変更しましたが、まだ同じ問題が発生しています。現在、データ アダプターを使用して、テキスト ボックスをプロパティ フィールドにバインドしています。オートコンプリート機能を本当に使いたい

Private Sub frmManageEquipment2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'AssetmgtDataSet.equipment' table. You can move, or remove it, as needed.
    Me.EquipmentTableAdapter.Fill(Me.AssetmgtDataSet.equipment)



    strSQL = "Select distinct(eq_Area) from Equipment order by eq_Area"
    txtArea.AutoCompleteMode = AutoCompleteMode.SuggestAppend
    txtArea.AutoCompleteSource = AutoCompleteSource.CustomSource
    sqlCommand = New MySqlCommand(strSQL, conn)
    Dim readerArea As MySqlDataReader = sqlCommand.ExecuteReader
    Dim sStringCollArea As New AutoCompleteStringCollection
    While readerArea.Read()
        sStringCollArea.AddRange(New String() {readerArea(0)})
    End While
    readerArea.Close()
    txtArea.AutoCompleteCustomSource = sStringCollArea


    strSQL = "Select distinct(eq_SubArea) from Equipment order by eq_SubArea"
    txtSubarea.AutoCompleteMode = AutoCompleteMode.SuggestAppend
    txtSubarea.AutoCompleteSource = AutoCompleteSource.CustomSource
    sqlCommand = New MySqlCommand(strSQL, conn)
    Dim readerSubArea As MySqlDataReader = sqlCommand.ExecuteReader
    Dim sStringCollSubArea As New AutoCompleteStringCollection
    While readerSubArea.Read()
****'This is where it goes back to the menu screen now****
        sStringCollSubArea.AddRange(New String() {readerSubArea(0)})
    End While
    readerSubArea.Close()
    txtSubarea.AutoCompleteCustomSource = sStringCollSubArea

End Sub
4

2 に答える 2

1

すべての SQL を別のスレッドに配置します。次に、form_load からスレッドを開始します。これで問題は解決するはずです。重い計算や DBMS コードなどを UI スレッドに配置することは、適切なプログラミング方法ではありません。UI と計算の両方で問題が発生します。

于 2013-12-18T10:58:38.913 に答える
0

最初にそのインスタンスを直接作成して呼び出さないでください

Dim nWindow As New frmManageEquipment2()
nWindow.Show()

Load イベントではなく Show イベントでコーディングを記述します。

于 2013-12-18T11:02:41.373 に答える