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 > ขอความกรุณาค่ะ ต้องการที่จะส่งข้อมูลจาก gridview1 ไปยัง gridview 2 ในฟอร์มเดียวกัน



 

ขอความกรุณาค่ะ ต้องการที่จะส่งข้อมูลจาก gridview1 ไปยัง gridview 2 ในฟอร์มเดียวกัน

 



Topic : 029490



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



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




ต้องการที่จะส่งข้อมูลจาก gridview1 ไปยัง gridview 2 ในฟอร์มเดียวกัน เช่น เมื่อเราเลือกข้อมูล จาก datagridview 1 แถวแรก ข้อมูลของ datagridview 1 แถวแรก ไปโชว์ที่ datagridview 2 ค่ะ ขอบคุณค่ะ เขียนด้วย vb.net 2008 ค่ะ



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-07-23 22:44:42 By : a View : 2384 Reply : 7
 

 

No. 1



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



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


Code (ASP)
<%
<asp:TemplateField HeaderText="Edit">
                                    <HeaderStyle HorizontalAlign="Center" Width="30px"/>
                                    <ItemTemplate>
                                        <asp:ImageButton ID="btnEdit" Width="20px" Height="20px" runat="server" ImageUrl='img/001_45.gif' ToolTip="Edit" OnClick="btnEdit_Click" CommandArgument='<%# DataBinder.Eval(Container, "DataItem.ProductSeq").ToString() %>' CausesValidation="false"/>
                                    </ItemTemplate>
                                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Bottom" />
                                </asp:TemplateField>
%>


//DataItem.ProductSeq คือข้อมูลที่อ้างอิงได้ว่ามาจากข้อมูล row ไหนในเทเบิล หรืออาจจะใช้ข้อมูลอื่นที่เป็น primary key ก็ได้ครับ ผมยกตัวอย่างกรณีของโปรแกรมผมนะครับขี้เกียจพิมพ์ใหม่

เมื่อกดที่ปุ่ม btnedit ก็จะได้ข้อมูลมา 1 row แล้วนะครับ
Code (C#)
protected void btnEdit_Click(object sender, EventArgs e)
    {
        ImageButton btnEdit = sender as ImageButton;
        GridViewRow row = (GridViewRow)btnEdit.NamingContainer;

        DataRow[] rowDetail = dtDetail.Select("ProductSeq = '" + btnEdit.CommandArgument.ToString() +"'"); //มาถึงตรงนี้จะได้ข้อมูลมา 1 row แล้วครับ ก็เอาไปทำการ add ลงอีก gridview นึง
    }







Date : 2009-07-24 10:06:46 By : besttooo
 


 

No. 2

Guest


ประมาณนี้ได้ไหมครับ
Code (VB.NET)
 '' ประกาศ C1 , C2 เป็น Global
    Private Sub DataGridView1_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
        If e.RowIndex = -1 Then Exit Sub
        If DataGridView1.CurrentRow.Index < pro.Rows.Count Then '' เทียบข้อมูลใน datagridview กับ  datatable
            With DataGridView1
                C1 = .Rows.Item(e.RowIndex).Cells(0).Value '' กรณี textbox, datetimepicker อยู่ในฟอร์มเดียวกัน
                C2 = .Rows.Item(e.RowIndex).Cells(1).Value
            End With
        End If

        Dim i As Integer = 0
        If C1 = "" Then Exit Sub ''check ข้อมูลใน C1 
        For i = 0 To DataGridView2.Rows.Count - 1
            With DataGridView2
                .Rows.Item(i).Cells(0).Value = C1
                .Rows.Item(i).Cells(1).Value = C2
            End With
        Next
    End Sub


select data from datagrid

ผิดพลาดประการใดขอ อภัย ด้วยครับ
tee
Date : 2009-07-24 18:02:27 By : lee_latee
 

 

No. 3



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



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


ยังไม่ได้เลยค่ะ ทำตามที่คุณ lee_latee บอกแล้วก็ยังไม่ได้เลยค่ะ มันไม่แสดงข้อมูล ใน datagridview ตัวที่2 ดังรูปที่คุณ lee_latee บอกค่ะ ยังไงช่วยหน่อยน่ะค่ะ ขอบคุณค่ะ
Date : 2009-07-25 23:48:00 By : a
 


 

No. 4



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



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

รบกวนขอดูโค้ดหน่อยครับ
Date : 2009-07-28 11:50:08 By : lee_latee
 


 

No. 5



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



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


Imports System.Data.SqlClient
Imports System.Data
Public Class FormCheckReceived
Dim conn As SqlConnection
Dim ds As DataSet
Dim c1, c2, c3, c4, c5, c6, c7 As Global.System.String
Dim IsFind As Boolean = False
Dim dt As DataTable


Private Sub FormCheckReceived_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New SqlClient.SqlConnection()
Dim cmd As New SqlClient.SqlCommand()

Dim sql2 As String = "SELECT id,date,order_id,pharmacist_id,supplier_id,quantity,total FROM received"
Dim cmd1 As New SqlClient.SqlCommand(sql2, conn)

Dim Result As New SqlCommand
Dim adapter As New SqlDataAdapter(cmd1)
Dim data As New DataSet()
conn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Documents and Settings\User\My Documents\Visual Studio 2008\Projects\PROJECT MORYA.mdf';Integrated Security=True;Connect Timeout=30;User Instance=True"
conn.Open()
cmd.Connection = conn


adapter.Fill(data, "received")
DataGridView1.DataSource = data.Tables("received")
'DataGridView1.Columns.Add("number", "number")
DataGridView1.Columns("id").HeaderText = "เลขที่ใบรับสินค้า"
DataGridView1.Columns("date").HeaderText = "วันที่รับสินค้า"
DataGridView1.Columns("order_id").HeaderText = "เลขที่ใบสั่งซื้อสินค้า"
DataGridView1.Columns("pharmacist_id").HeaderText = "รหัสเภสัชกร"
DataGridView1.Columns("supplier_id").HeaderText = "รหัสตัวแทนจำหน่าย"
DataGridView1.Columns("quantity").HeaderText = "จำนวน"
DataGridView1.Columns("total").HeaderText = "รวมเป็นเงิน"
'...............................................................................
conn.Close()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim com As New SqlCommand
Dim conn As New SqlClient.SqlConnection()
Dim cmd As New SqlClient.SqlCommand()
conn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Documents and Settings\User\My Documents\Visual Studio 2008\Projects\PROJECT MORYA.mdf';Integrated Security=True;Connect Timeout=30;User Instance=True"
conn.Open()
com.CommandText = "Select * from received"
com.CommandType = CommandType.StoredProcedure
com.Connection = conn
cmd.Connection = conn
cmd.CommandText = ""
'cmd.ExecuteNonQuery()

Dim da As New SqlDataAdapter(com)
Dim ds As New DataSet
da.SelectCommand.Parameters.Add("BeginDate", SqlDbType.Date).Value = dtpstart.Value.ToString("s")
da.SelectCommand.Parameters.Add("EndingDate", SqlDbType.Date).Value = dtpend.Value.ToString("s")
If (IsFind = True) Then
ds.Tables("recevied").Clear()
End If
da.Fill(ds, "received")
If ds.Tables("recevied").Rows.Count <> 0 Then
IsFind = True
DataGridView1.ReadOnly = True
DataGridView1.DataSource = ds.Tables("received")
Else
IsFind = False
MessageBox.Show("ช่วงเวลาที่คุณระบุ ไม่มีรายการขาย", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

Dim MyString As String = "12345"
Dim MyInt As Integer = Integer.Parse(MyString)
MyInt += 1
Console.WriteLine(MyInt)
' The result is "12346".

conn.Close()
End Sub

Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
process.Visible = True
End Sub

Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
process.Visible = False
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
If MessageBox.Show("ต้องการออกจากการตรวจสอบการรับสินค้าใช่หรือไม่", "ออกจากระบบ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = vbYes Then
Me.Close()
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
If Me.DataGridView1.Rows.Count - 1 > 0 Then
If Not DataGridView1.CurrentRow.IsNewRow Then
MessageBox.Show("คุณต้องการลบข้อมูลใช่หรือไม่", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Question)
DataGridView1.Rows.Remove(DataGridView1.CurrentRow)
Else
MsgBox("Is Noting DATA", MsgBoxStyle.Information)
End If
Else
MsgBox("Is Not DATA", MsgBoxStyle.Information)
End If

Me.Cursor = Cursors.Default
End Sub


Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting


Dim j As Integer = 0 '' วิธีแรกครับ
Dim SumPrice As Double = 0
For j = 0 To DataGridView1.Rows.Count - 1
SumPrice += CDbl(DataGridView1.Rows(j).Cells(6).Value)
Next
sales_total.Text = SumPrice.ToString("#,##0.00")

'...........แสดงจำนวนแถวใน datagridview..............................
TextBox2.Text = "" + DataGridView1.Rows.Count.ToString()
'................................................................


End Sub

Private Sub DataGridView1_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
If e.RowIndex = -1 Then Exit Sub
If DataGridView1.CurrentRow.Index < DataGridView1.Rows.Count Then '' เทียบข้อมูลใน datagridview กับ datatable
With (DataGridView1)
c1 = .Rows.Item(e.RowIndex).Cells(0).Value '' กรณี textbox, datetimepicker อยู่ในฟอร์มเดียวกัน
c2 = .Rows.Item(e.RowIndex).Cells(1).Value
c3 = .Rows.Item(e.RowIndex).Cells(2).Value
c4 = .Rows.Item(e.RowIndex).Cells(3).Value
c5 = .Rows.Item(e.RowIndex).Cells(4).Value
c6 = .Rows.Item(e.RowIndex).Cells(5).Value
c7 = .Rows.Item(e.RowIndex).Cells(6).Value
End With
End If
Dim i As Integer = 0
If c1 = "" Then Exit Sub ''check ข้อมูลใน C1
For i = 0 To DataGridView2.Rows.Count - 1
With (DataGridView2)
.Rows.Item(i).Cells(0).Value = c1
.Rows.Item(i).Cells(1).Value = c2
.Rows.Item(i).Cells(0).Value = c3
.Rows.Item(i).Cells(1).Value = c4
.Rows.Item(i).Cells(0).Value = c5
.Rows.Item(i).Cells(1).Value = c6
.Rows.Item(i).Cells(1).Value = c7
End With
Next

End Sub

Private Sub DataGridView1_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDoubleClick

If e.RowIndex = -1 Then Exit Sub
If DataGridView1.CurrentRow.Index < DataGridView2.Rows.Count Then '' เทียบข้อมูลใน datagridview กับ datatable
With (DataGridView1)
c1 = .Rows.Item(e.RowIndex).Cells(0).Value '' กรณี textbox, datetimepicker อยู่ในฟอร์มเดียวกัน
c2 = .Rows.Item(e.RowIndex).Cells(1).Value
c3 = .Rows.Item(e.RowIndex).Cells(2).Value
c4 = .Rows.Item(e.RowIndex).Cells(3).Value
c5 = .Rows.Item(e.RowIndex).Cells(4).Value
End With
End If
Dim i As Integer = 0
If c1 = "" Then Exit Sub ''check ข้อมูลใน C1
For i = 0 To DataGridView2.Rows.Count - 1
With (DataGridView2)
.Rows.Item(i).Cells(0).Value = c1
.Rows.Item(i).Cells(1).Value = c2
.Rows.Item(i).Cells(2).Value = c3
.Rows.Item(i).Cells(3).Value = c4
.Rows.Item(i).Cells(4).Value = c5
End With
Next
End Sub

Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
'................แสดงหมายเลขลำดับที่...............
Using b As SolidBrush = New SolidBrush(Me.DataGridView1.RowHeadersDefaultCellStyle.ForeColor)

e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), _
Me.DataGridView1.DefaultCellStyle.Font, _
b, e.RowBounds.Location.X + 5, _
e.RowBounds.Location.Y + 5)
End Using

End Sub

Private Sub DataGridView2_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView2.RowPostPaint
'................แสดงหมายเลขลำดับที่...............

Using b As SolidBrush = New SolidBrush(Me.DataGridView2.RowHeadersDefaultCellStyle.ForeColor)

e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), _
Me.DataGridView2.DefaultCellStyle.Font, _
b, e.RowBounds.Location.X + 5, _
e.RowBounds.Location.Y + 5)
End Using
End Sub
End Class
Date : 2009-07-28 14:44:54 By : a
 


 

No. 6



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



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


ช่วยหน่อยน่ะค่ะ ไม่ค่อยถนัดเลย
Date : 2009-07-28 14:45:32 By : a
 


 

No. 7

Guest


คุณ lee_latee ครับ มันไม่รู้จักตัวนี้ครับ pro.Rows.Count แต่ Code ที่นำไปใช้ ใช้ได้ครับ ถ้าตัดตัวนี้ออกไป แต่ก็มีบัคตรงที่ว่าถ้าไปคลิกบริเวณส่วนหัวหรือท้ายสุดมันจะ Error ครับ
Date : 2009-07-30 11:48:50 By : zerocool
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขอความกรุณาค่ะ ต้องการที่จะส่งข้อมูลจาก gridview1 ไปยัง gridview 2 ในฟอร์มเดียวกัน
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 03
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 อัตราราคา คลิกที่นี่