none
如何將在TabControl下的DataGridView的值,傳回到Form的DataGridView呢? RRS feed

  • 一般討論

  • 請問如何將TabControl下TabPages裡查詢到的DataGridView3的 第二行(1),第三行(2),第四行(3)資料,在按下Button後

    傳到同一個Form的DataGridView1裡的第一行(0),第二行(1),第九行(8)呢?

    Form的DataGridView的資料原是先清除的!

     

    程式碼區塊

    Private Sub Form5111_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                   

            Dim cmmd As New SqlClient.SqlCommand
            cmmd = New SqlClient.SqlCommand("SELECT  B_CprPInvertory.LocationID AS 物料格編號,A_Component.ComponentID AS 物料編號,B_CprPInvertory.DPNum AS 入庫數量,B_CprPInvertory.FormID AS 請購單編號,B_CprPInvertory.VendorName AS 廠商名稱,A_Component.UPrice AS 單價,B_CprPInvertory.BatchNo AS 批號,B_CprPInvertory.Remark AS 備註,A_Component.Component AS 物料名稱 FROM A_Component INNER JOIN B_CprPInvertory ON A_Component.ComponentID = dbo.B_CprPInvertory.ComponentID", cn)
            da.SelectCommand = cmmd
            ds = New DataSet
            da.Fill(ds, "A_component")
            ds.Tables("A_component").Clear()
            DataGridView1.DataSource = ds.Tables("A_component")

    '作業清單的DataGridView
            LocDataGridView.DataSource = LocBindingSource
            'DataDataGridView.DataSource = DataBindingSource
            'CompDataGridView.DataSource = CompBindingSource
            t = CMMS1DataSet.Loc.Rows(0)(1)

            ds = New DataSet
            Dim cmd As New SqlClient.SqlCommand("select SetUpID as 上層編號,SetSysID as 儲存空間編號,SetName as 空間說明 from D_InvIndex", cn)
            da.SelectCommand = cmd
            da.Fill(ds, "InvIndex2")
            ds.Tables("InvIndex2").Clear()
            cmd = New SqlClient.SqlCommand("select D_InvIndex.SetUpID AS 上層編號,D_InvIndex.SetSysID AS 儲存空間編號,D_InvIndex.ComponentID AS 物料編號,A_Component.Component AS 物料名稱,A_Component.Specification AS 規格,D_InvIndex.Num AS 庫存量 FROM D_InvIndex INNER JOIN A_Component ON D_InvIndex.ComponentID = A_Component.ComponentID WHERE D_InvIndex.SetLevelNo = 5", cn)
            da.SelectCommand = cmd
            da.Fill(ds, "InvIndex3")
            ds.Tables("InvIndex3").Clear()

     

    //Form5111-Button1

    程式碼區塊

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            ''按下加入清單後,查詢到的物料編號會show到DataGridView1
            Dim cn As New SqlClient.SqlConnection("server=.;database=cmms1;uid=sa;password=sescsapw")
            Dim cmd As New SqlClient.SqlCommand("SELECT  B_CprPInvertory.LocationID AS 物料格編號,A_Component.ComponentID AS 物料編號,B_CprPInvertory.DPNum AS 入庫數量,B_CprPInvertory.FormID AS 請購單編號,B_CprPInvertory.VendorName AS 廠商名稱,A_Component.UPrice AS 單價,B_CprPInvertory.BatchNo AS 批號,B_CprPInvertory.Remark AS 備註,A_Component.Component AS 物料名稱 FROM A_Component INNER JOIN B_CprPInvertory ON A_Component.ComponentID = dbo.B_CprPInvertory.ComponentID", cn)
            da = New SqlDataAdapter
            ds = New DataSet
            da.SelectCommand = cmd

            da.Fill(ds, "B_CprPInvertor")
            DataGridView1.Columns.Clear()
            DataGridView1.DataSource = ds.Tables("B_CprPInvertor")

     

     

    因為是在TabControl作的動作,附上之前程式

    程式碼區塊

    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
            Dim tb As TabControl = CType(sender, TabControl)
            Select Case (tb.SelectedIndex)
                Case 0

                Case 1              '儲位別'
                    If t <> "" Then
                        If t IsNot Nothing Then
                            Dim cmd As New SqlClient.SqlCommand("select SetUpID as 上層編號,SetSysID as 儲存空間編號,SetName as 空間說明 from D_InvIndex WHERE SetLevelNo = 4 and SetUpID='" + t + "'", cn)
                            da.SelectCommand = cmd
                            Dim tt As DataTable = ds.Tables("InvIndex2")
                            If tt IsNot Nothing Then tt.Clear()
                            da.Fill(ds, "InvIndex2")
                            DataDataGridView.DataSource = ds.Tables("InvIndex2")
                        Else
                            t1 = ""
                            ds.Tables("InvIndex2").Clear()
                        End If
                    Else
                        ds.Tables("InvIndex2").Clear()
                        DataDataGridView.DataSource = ds.Tables("InvIndex2")
                    End If
                Case 2              '物料別'
                    If t = "" OrElse ds.Tables("InvIndex2").Rows.Count = 0 Then
                        ds.Tables("InvIndex3").Clear()
                        CompDataGridView.DataSource = ds.Tables("InvIndex3")
                    Else
                        If t1 IsNot Nothing Then
                            Dim cmd As New SqlClient.SqlCommand("select D_InvIndex.SetUpID AS 上層編號,D_InvIndex.SetSysID AS 儲存空間編號,D_InvIndex.ComponentID AS 物料編號,A_Component.Component AS 物料名稱,A_Component.Specification AS 規格,D_InvIndex.Num AS 庫存量 FROM D_InvIndex INNER JOIN A_Component ON D_InvIndex.ComponentID = A_Component.ComponentID WHERE D_InvIndex.SetLevelNo = 5 and D_InvIndex.SetUpID='" + t1 + "'", cn)
                            da.SelectCommand = cmd
                            Dim tt As DataTable = ds.Tables("InvIndex3")
                            If tt IsNot Nothing Then tt.Clear()
                            da.Fill(ds, "InvIndex3")
                            CompDataGridView.DataSource = ds.Tables("InvIndex3")
                        End If
                    End If
            End Select
           
        End Sub

     

     

    • 已變更類型 璉璉Moderator 2010年2月27日 下午 04:03
    • 已移動 璉璉Moderator 2010年2月27日 下午 04:03 (從:Visual Studio一般討論區(General))
    2007年11月14日 上午 09:27