7 Replies - 513 Views - Last Post: 23 April 2012 - 12:41 AM Rate Topic: -----

#1 Iamateur  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 62
  • Joined: 20-April 12

Ggridview1 row display on gridview 2

Posted 21 April 2012 - 10:27 PM

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.

Is This A Good Question/Topic? 0
  • +

Replies To: Ggridview1 row display on gridview 2

#2 artemix22  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 124
  • Joined: 21-January 12

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

Was This Post Helpful? 0
  • +
  • -

#3 Iamateur  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 62
  • Joined: 20-April 12

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.
Was This Post Helpful? 0
  • +
  • -

#4 artemix22  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 124
  • Joined: 21-January 12

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.
Was This Post Helpful? 0
  • +
  • -

#5 Iamateur  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 62
  • Joined: 20-April 12

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
Was This Post Helpful? 0
  • +
  • -

#6 Iamateur  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 62
  • Joined: 20-April 12

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
Was This Post Helpful? 0
  • +
  • -

#7 artemix22  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 124
  • Joined: 21-January 12

Re: Ggridview1 row display on gridview 2

Posted 22 April 2012 - 10:57 PM

View PostIamateur, 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


delete Me.

DataGridView2.DataSource = dt


This post has been edited by artemix22: 22 April 2012 - 10:59 PM

Was This Post Helpful? 0
  • +
  • -

#8 Iamateur  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 62
  • Joined: 20-April 12

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 :


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'.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1