datagridview select row and pass to another datagridview


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: datagridview select row and pass to another datagridview

Hybrid View

  1. #1
    Join Date
    Jan 2010
    Posts
    8

    datagridview select row and pass to another datagridview

    hi guys i need some help if anyone can

    i populate datagridview1 with an sql query and datagridview2 with another sql query. i have to select a row from datagridview1 and on button1 click to pass the row at datagrid2 and the same for datagridview2. select a row from datagrid2 and on button2 click to pass the row at datagridview1

    i have no idea how to do this, i welcome any help

  2. #2
    Join Date
    Jul 2004
    Posts
    365
    This is a very basic and shabby way, but you'll get the idea. Only goes from 1st datagrid to the 2nd. You'll have to play and get it to go from 2nd to 1st.


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

    dgv1.Columns.Add("Test", "TestColumn")

    dgv1.Rows.Add(1)

    dgv1.Rows(0).Cells("Test").Value = "Help Me"

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim strText As String = dgv1.SelectedCells(0).Value

    dgv2.Columns.Add("Test", "TestColumn")

    dgv2.Rows.Add(1)

    dgv2.Rows(0).Cells("Test").Value = strText


    End Sub

  3. #3
    Join Date
    Jan 2010
    Posts
    8
    jcb thanks for the code but it helped me find out that i need to create a DataTable first and the row there and them bind it to dgv1.

    so wrote some code but doesnt work, if you can check it

    Dim copytable As New DataTable
    'Dim Row1 As DataRow
    'declaring a row for the copytable
    Try
    Dim foititis_onoma As DataColumn = New DataColumn("foititis_onoma")
    ' declaring a column named Name
    foititis_onoma.DataType = System.Type.GetType("System.String")
    'setting the datatype for the column
    copytable.Columns.Add(Name)
    'adding the column to table
    Dim foititis_eponymo As DataColumn = New DataColumn("foititis_eponymo")
    foititis_eponymo.DataType = System.Type.GetType("System.String")
    copytable.Columns.Add(foititis_eponymo)



    If Not DataGridView1.CurrentRow.IsNewRow Then

    DataGridView1.Rows.Remove(DataGridView1.CurrentRow)

    copytable.BeginLoadData() 'DataGridView2.Rows.Add()

    For Each row As DataGridViewRow In DataGridView1.SelectedRows

    Dim Row1 As DataRow = copytable.NewRow

    Row1("foititis_onoma") = row.Cells("foititis_onoma").Value
    Row1("foititis_eponymo") = row.Cells("foititis_eponymo").Value
    copytable.Rows.Add(Row1)
    Next

    copytable.Rows.Add(DataGridView1.CurrentRow)
    copytable.AcceptChanges()
    copytable.EndLoadData()

    Dim dv2 As DataView = New DataView(copytable)
    DataGridView2.DataSource = dv2

    End If
    Catch
    End Try

Similar Threads

  1. row level triggers
    By Ervin Rodriguez in forum Database
    Replies: 3
    Last Post: 02-07-2002, 06:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center