Results 1 to 12 of 12

Thread: [RESOLVED] DataGrids data transfer between

  1. #1
    Lively Member Black_Trouble's Avatar
    Join Date
    Feb 12
    Posts
    88

    Lightbulb [RESOLVED] DataGrids data transfer between

    There are two forms. form1, form2 opens when I press a datagrid cell. I chose the datagrid form2, form1 data overwrite the active cell.

    so that

    Name:  datagrid.jpg
Views: 48
Size:  157.7 KB

    Thank you in advance for your help.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,785

    Re: DataGrids data transfer between

    How exactly are the two grids populated?

  3. #3
    Lively Member Black_Trouble's Avatar
    Join Date
    Feb 12
    Posts
    88

    Re: DataGrids data transfer between

    comes from sql database in form2 grid. form1 is filled manually in the grid. I'm gonna go where the grid pressing the button in form1, form2 selected in the grid.
    the active cell in the grid button on form1 1.column occurs. Please click on the calculator window is opened to him.

  4. #4
    Lively Member Black_Trouble's Avatar
    Join Date
    Feb 12
    Posts
    88

    Re: DataGrids data transfer between

    Name:  datagrid.jpg
Views: 32
Size:  94.1 KB

    I hope I am able to stop.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,785

    Re: DataGrids data transfer between

    In the dialogue form you would want to declare a property. That property should return the Value from the appropriate cell of the CurrentRow of the grid. On your first form, you can call ShowDialog on the second form and, when it returns, get the aforementioned property value and assign it to the Value of the CurrentCell.

  6. #6
    Lively Member Black_Trouble's Avatar
    Join Date
    Feb 12
    Posts
    88

    Re: DataGrids data transfer between

    Can you write code in form1 and form2. I tried to do, but somehow I could not. It just could not find an idea of ​​where to start.

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,785

    Re: DataGrids data transfer between

    Here's the ideas where to start:
    In the dialogue form you would want to declare a property.
    On your first form, you can call ShowDialog on the second form
    Do you know how to declare a property? If not then that would be the first thing to investigate.

    https://www.google.com.au/search?q=d...ient=firefox-a

    Do you know how to call ShowDialog? If not then that would be the next thing to investigate.

    https://www.google.com.au/search?q=s...ient=firefox-a

    As you can see, there's lots that you can do for yourself rather than just waiting for the information to come to you. I'm not big on providing code to just copy and paste because that often teaches very little. The best way to learn is to do. I'm more than happy to help if there are problems along the way but there's already a whole WWW out there so, given a point in the right direction, it's rare that you should need someone else to just write all the code for you.

  8. #8
    Lively Member Black_Trouble's Avatar
    Join Date
    Feb 12
    Posts
    88

    Re: DataGrids data transfer between

    a kind of teacher could be so nice to think you need a hand


    datagrid dialog.rar

  9. #9
    Lively Member Black_Trouble's Avatar
    Join Date
    Feb 12
    Posts
    88

    Re: DataGrids data transfer between

    Form1 Vb.Net Code:

    Code:
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            DataGridView1.Rows.Add(14)
        End Sub
    
        Private Sub DataGridView1_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles DataGridView1.CellBeginEdit
            Dim bt As Button = New Button
            If DataGridView1.CurrentCell.ColumnIndex = 0 Then
                bt.Tag = e.RowIndex
                bt.Text = "..."
                bt.Width = 22
                AddHandler bt.Click, AddressOf Me.datagridclick
                DataGridView1.Controls.Add(bt)
                Dim cell As Rectangle = Me.DataGridView1.GetCellDisplayRectangle(0, e.RowIndex, True)
                bt.Location = New Point((cell.Right - bt.Width), cell.Top)
    
            Else
                DataGridView1.Controls.Clear()
            End If
        End Sub
    
        Private Sub datagridclick(ByVal sender As Object, ByVal e As EventArgs)
            Dim frm As Form2 = New Form2
            frm.anaform = Me
            frm.ShowDialog()
        End Sub
    
        Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
            DataGridView1.Controls.Clear()
        End Sub
    
    End Class

    Form2 VB.Net Code:

    Code:
    Imports System.Data.SqlClient
    
    Public Class Form2
        Public anaform As Form1
        Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
    
                Dim baglanti As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=" + Application.StartupPath + "\database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
            If baglanti.State = ConnectionState.Closed Then baglanti.Open()
                Dim cmd As New SqlCommand("select * from veriler", baglanti)
            Dim adapter As New SqlDataAdapter(cmd)
            Dim dt As New DataTable()
            adapter.Fill(dt)
            DataGridView1.DataSource = dt
                baglanti.Close()
            Catch ex As Exception
    
            End Try
        End Sub
        Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
            anaform.DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells(0).Value = DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells(0).Value.ToString
            Me.Close()
        End Sub
    End Class
    I did, but he was a problem. active cell is not going to a different cell.

  10. #10
    Lively Member Black_Trouble's Avatar
    Join Date
    Feb 12
    Posts
    88

    Re: DataGrids data transfer between

    the problem continues. Can you help.

  11. #11
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,785

    Re: DataGrids data transfer between

    Here's an example of why you should use proper descriptive names for everything and not accept the default names like DataGridView1.
    Code:
    anaform.DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells(0).Value = DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells(0).Value.ToString
    You are indexing the grid on the first form using the current cell from the second form. If your grids had proper names then it would have been obvious that you were using the wrong one.

    That said, why do this:
    Code:
    DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex)
    when you can do this:
    Code:
    DataGridView1.CurrentRow

  12. #12
    Lively Member Black_Trouble's Avatar
    Join Date
    Feb 12
    Posts
    88

    Re: DataGrids data transfer between

    Thank you very much. the problem is solved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •