I have created 2 gridviews.
In gridview1 the database table is displayed.
The gridview1 is used to show the books list.
It is used to search books.
Once the user chooses the row then that selected row should get displayed in the other gridview2 with the additional columns->details like date of issue,date of return and other details.
I thought to do the coding for this in button itself by adding button on gridview1.
I tried to do this but not able to do it.
Can anybody help me out.
Thanks.
Ggridview1 row display on gridview 2
Page 1 of 17 Replies - 513 Views - Last Post: 23 April 2012 - 12:41 AM
Replies To: Ggridview1 row display on gridview 2
#2
Re: Ggridview1 row display on gridview 2
Posted 21 April 2012 - 11:38 PM
in event Selectionchanged for DGV1, put this Query :
Using conn As New SqlConnection("Connection's String")
conn.Open()
Dim command As New SqlCommand("select * from table_name where column_name = '" & Me.DataGridView1.CurrentRow.Cell(index of colomn DGV1 where selected).value & "'", conn)
Dim Adapter As New SqlDataAdapter
Dim dt As New Data Table
Adapter.SelectCommand = command
Adapter.Fill(dt)
Me.DataGridView2.DataSource = dt
adapter.Dispose()
command.Dispose()
conn.Close()
End Using
This post has been edited by artemix22: 21 April 2012 - 11:51 PM
#3
Re: Ggridview1 row display on gridview 2
Posted 22 April 2012 - 04:33 AM
Dim command As New SqlCommand("select * from table_name where column_name = '" & Me.DataGridView1.CurrentRow.Cell(index of colomn DGV1 where selected).value & "'", conn)
In the above line its giving error as cell is not a member of System.Windows.Forms.DataGridViewRow.
In the above line its giving error as cell is not a member of System.Windows.Forms.DataGridViewRow.
#4
Re: Ggridview1 row display on gridview 2
Posted 22 April 2012 - 05:01 AM
gezz.. what i mean is "cells" not "cell", of course it will give you an error, i didn't test it before, but it should work.
#5
Re: Ggridview1 row display on gridview 2
Posted 22 April 2012 - 06:01 AM
Ya I used it as Cells.
And aafter using Cells it gives error as value is not a member of System.Windows.Forms.DataGridViewCellCollection
I am doing this in vb net 3.5
In between may I know why did u use Me?
As I have got MDIParent and its code is :
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ChildForm As New System.Windows.Forms.Form
ChildForm.MdiParent = Me
End Sub
And aafter using Cells it gives error as value is not a member of System.Windows.Forms.DataGridViewCellCollection
I am doing this in vb net 3.5
In between may I know why did u use Me?
As I have got MDIParent and its code is :
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ChildForm As New System.Windows.Forms.Form
ChildForm.MdiParent = Me
End Sub
#6
Re: Ggridview1 row display on gridview 2
Posted 22 April 2012 - 06:46 AM
Now I wrote it in this way:
[Me].DataGridView1.CurrentRow.Cells.value
So its giving the error as Name 'Me' is not declared.
My question is instead of using Me can I use some other word.
Because there is Mdiparent form also in the same project so I have written as :
Dim ChildForm As New System.Windows.Forms.Form
ChildForm.MdiParent = Me
[Me].DataGridView1.CurrentRow.Cells.value
So its giving the error as Name 'Me' is not declared.
My question is instead of using Me can I use some other word.
Because there is Mdiparent form also in the same project so I have written as :
Dim ChildForm As New System.Windows.Forms.Form
ChildForm.MdiParent = Me
#7
Re: Ggridview1 row display on gridview 2
Posted 22 April 2012 - 10:57 PM
Iamateur, on 22 April 2012 - 06:46 AM, said:
Now I wrote it in this way:
[Me].DataGridView1.CurrentRow.Cells.value
So its giving the error as Name 'Me' is not declared.
My question is instead of using Me can I use some other word.
Because there is Mdiparent form also in the same project so I have written as :
Dim ChildForm As New System.Windows.Forms.Form
ChildForm.MdiParent = Me
[Me].DataGridView1.CurrentRow.Cells.value
So its giving the error as Name 'Me' is not declared.
My question is instead of using Me can I use some other word.
Because there is Mdiparent form also in the same project so I have written as :
Dim ChildForm As New System.Windows.Forms.Form
ChildForm.MdiParent = Me
delete Me.
DataGridView2.DataSource = dt
This post has been edited by artemix22: 22 April 2012 - 10:59 PM
#8
Re: Ggridview1 row display on gridview 2
Posted 23 April 2012 - 12:41 AM
artemix22
I am telling u that error is at this line
[Me].DataGridView1.CurrentRow.Cells.value
So its giving the error as Name 'Me' is not declared.
And your suggesting to delete from other line :
[/quote]
I did as you suggested but anyways the errors are either the above one or else the below one:
After removing brackets:
Dim cmd As New SqlCommand("select * from MBA where bname='" + Me.DataGridView1.CurrentRow.Cells.value + "'", con)
Error 1 'value' is not a member of 'System.Windows.Forms.DataGridViewCellCollection'.
I am telling u that error is at this line
[Me].DataGridView1.CurrentRow.Cells.value
So its giving the error as Name 'Me' is not declared.
And your suggesting to delete from other line :
DataGridView2.DataSource = dt
[/quote]
I did as you suggested but anyways the errors are either the above one or else the below one:
After removing brackets:
Dim cmd As New SqlCommand("select * from MBA where bname='" + Me.DataGridView1.CurrentRow.Cells.value + "'", con)
Error 1 'value' is not a member of 'System.Windows.Forms.DataGridViewCellCollection'.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|