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.
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.
How exactly are the two grids populated?
2007-2013
Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB (*NEW* Pausing Code) | C#
My Blog: Using Parameters in ADO.NET | Keyboard Events | Assemblies & Namespaces
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.
I hope I am able to stop.
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.
2007-2013
Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB (*NEW* Pausing Code) | C#
My Blog: Using Parameters in ADO.NET | Keyboard Events | Assemblies & Namespaces
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.
Here's the ideas where to start:In the dialogue form you would want to declare a property.Do you know how to declare a property? If not then that would be the first thing to investigate.On your first form, you can call ShowDialog on the second form
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.
2007-2013
Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB (*NEW* Pausing Code) | C#
My Blog: Using Parameters in ADO.NET | Keyboard Events | Assemblies & Namespaces
a kind of teacher could be so nice to think you need a hand
datagrid dialog.rar
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:
I did, but he was a problem. active cell is not going to a different cell.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
the problem continues. Can you help.
Here's an example of why you should use proper descriptive names for everything and not accept the default names like DataGridView1.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.Code:anaform.DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells(0).Value = DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells(0).Value.ToString
That said, why do this:when you can do this:Code:DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex)Code:DataGridView1.CurrentRow
2007-2013
Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB (*NEW* Pausing Code) | C#
My Blog: Using Parameters in ADO.NET | Keyboard Events | Assemblies & Namespaces
Thank you very much. the problem is solved