|
-
Sep 9th, 2012, 03:32 PM
#1
Thread Starter
Lively Member
[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

Thank you in advance for your help.
-
Sep 9th, 2012, 07:58 PM
#2
Re: DataGrids data transfer between
How exactly are the two grids populated?
-
Sep 10th, 2012, 01:29 AM
#3
Thread Starter
Lively Member
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.
-
Sep 10th, 2012, 01:34 AM
#4
Thread Starter
Lively Member
Re: DataGrids data transfer between

I hope I am able to stop.
-
Sep 10th, 2012, 01:39 AM
#5
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.
-
Sep 10th, 2012, 02:06 AM
#6
Thread Starter
Lively Member
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.
-
Sep 10th, 2012, 02:15 AM
#7
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.
-
Sep 10th, 2012, 06:28 AM
#8
Thread Starter
Lively Member
Re: DataGrids data transfer between
a kind of teacher could be so nice to think you need a hand
datagrid dialog.rar
-
Sep 10th, 2012, 06:57 AM
#9
Thread Starter
Lively Member
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.
-
Sep 11th, 2012, 02:28 AM
#10
Thread Starter
Lively Member
Re: DataGrids data transfer between
the problem continues. Can you help.
-
Sep 11th, 2012, 02:38 AM
#11
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
-
Sep 11th, 2012, 03:33 AM
#12
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|