Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > ช่วยดูให้หน่อยครับว่าผิดพลาดตรงไหนการCopyจากdatagridview1ไปยังdatagridview2



 

ช่วยดูให้หน่อยครับว่าผิดพลาดตรงไหนการCopyจากdatagridview1ไปยังdatagridview2

 



Topic : 130764



โพสกระทู้ ( 47 )
บทความ ( 0 )



สถานะออฟไลน์




copy

อันนี้เป็นโค้ดในปุ่มกดที่จะให้copyจาก1ไปยัง2

Code (VB.NET)
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        For Each bos As DataGridViewRow In DataGridView1.Rows
            DataGridView2.Rows.Add()
            For Each row As DataGridViewColumn In DataGridView2.Columns
                DataGridView1.Rows(0).Cells(row.Index).Value = DataGridView2.Rows(bos.Index).Cells(row.Index).Value.ToString
            Next
        Next
    End Sub




Tag : .NET, VB.NET







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2018-04-04 20:26:32 By : 1354452254604116 View : 810 Reply : 3
 

 

No. 1



โพสกระทู้ ( 119 )
บทความ ( 3 )



สถานะออฟไลน์
Facebook

แอดตารางเดียว โดยไม่ตรวจว่ามันจะซ้ำหรือไม่

Code (VB.NET)
        Dim rc As Integer = Me.DataGridView2.Rows.Count
        Me.DataGridView2.Rows.Add()
        Me.DataGridView2.Rows(rc).Cells(0).Value = Me.DataGridView1.CurrentRow.Cells(0).Value
        Me.DataGridView2.Rows(rc).Cells(1).Value = Me.DataGridView1.CurrentRow.Cells(1).Value


แอดตารางเดียว โดยตรวจว่ามันมีตารางซ้ำหรือไม่

Code (VB.NET)
For r As Integer = 0 To Me.DataGridView2.Rows.Count - 1
            If Me.DataGridView1.CurrentRow.Cells(0).Value = Me.DataGridView2.Rows(r).Cells(0).Value Then
                Exit For
            End If
            Dim rc As Integer = Me.DataGridView2.Rows.Count
            Me.DataGridView2.Rows.Add()
            Me.DataGridView2.Rows(rc).Cells(0).Value = Me.DataGridView1.CurrentRow.Cells(0).Value
            Me.DataGridView2.Rows(rc).Cells(1).Value = Me.DataGridView1.CurrentRow.Cells(1).Value
        Next


แอดหลายตารางโดยไม่ตรวจว่ามันซ้ำหรือไม่

Code (VB.NET)
      For Each row As DataGridViewRow In DataGridView1.Rows
            If row.Selected = True Then
                Dim rc As Integer = Me.DataGridView2.Rows.Count
                Me.DataGridView2.Rows.Add()
                Me.DataGridView2.Rows(rc).Cells(0).Value = row.Cells(0).Value
                Me.DataGridView2.Rows(rc).Cells(1).Value = row.Cells(1).Value
            End If
        Next


แอดหลายตาราง โดยตรวจว่ามันซ้ำกันหรือไม่

Code (VB.NET)
        For Each row As DataGridViewRow In DataGridView1.Rows
            If row.Selected = True Then
                For Each row2 As DataGridViewRow In DataGridView2.Rows
                    If row.Cells(0).Value = row2.Cells(0).Value Then
                        GoTo GotoNoAddRow
                    End If
                Next row2
                Dim rc As Integer = Me.DataGridView2.Rows.Count
                Me.DataGridView2.Rows.Add()
                Me.DataGridView2.Rows(rc).Cells(0).Value = row.Cells(0).Value
                Me.DataGridView2.Rows(rc).Cells(1).Value = row.Cells(1).Value
GotoNoAddRow:
            End If
        Next









ประวัติการแก้ไข
2018-04-05 08:34:58
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-04-05 08:34:02 By : pakyaudio
 


 

No. 2



โพสกระทู้ ( 47 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 1 เขียนโดย : pakyaudio เมื่อวันที่ 2018-04-05 08:34:02
รายละเอียดของการตอบ ::
ได้ละครับ ผมใช้ แบบนี้

Code (VB.NET)
     For iRow = 0 To DataGridView1.Rows.Count - 1
            Dim row As String() = New String() {DataGridView1.Rows(iRow).Cells(0).Value, DataGridView1.Rows(iRow).Cells(1).Value, DataGridView1.Rows(iRow).Cells(2).Value}
            DataGridView2.Rows.Add(row)
        Next


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-04-05 10:58:38 By : 1354452254604116
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-04-16 11:53:16 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยดูให้หน่อยครับว่าผิดพลาดตรงไหนการCopyจากdatagridview1ไปยังdatagridview2
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่