9 Replies - 1681 Views - Last Post: 11 October 2011 - 11:23 AM Rate Topic: -----

#1 huskyfritz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 04-July 09

Datagridview to textbox

Post icon  Posted 14 July 2009 - 01:47 AM

Hi guys!

I am new in Vb.net and I am still studying this language.

I am trying to retrive data to a textbox from a datagridview.

I have Tabcontrol with two tabs naming Data Sheet View and Form View.
The datagridview is in Data Sheet view while my textboxes are in Form View.

Al I want is that everytime I click on the data in datagridview, it would display in textbox in form view.

Here are some of my code:

Dim ret As String = "select * from newstudent_tbl where USN='" & DataGridView1.SelectedCells(0).ToString & "'"
		cmd.CommandText = ret
		cmd.Connection = oConn
		oConn.Open()
		dr = cmd.ExecuteReader
		
		If dr.HasRows Then

			Do While dr.Read


				TextBox2.Text = dr(0)
				TextBox4.Text = dr(1)
				

			Loop

		End If
		oConn.Close()

		cmd.Dispose()
		oConn.Dispose()



Can you help me guys solve this problem??

thanks in advance!
:D

Is This A Good Question/Topic? 0
  • +

Replies To: Datagridview to textbox

#2 daxriders  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 25
  • Joined: 08-July 09

Re: Datagridview to textbox

Posted 14 July 2009 - 06:58 AM

have you tried using a typed dataset? (through the data source window)
Was This Post Helpful? 0
  • +
  • -

#3 huskyfritz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 04-July 09

Re: Datagridview to textbox

Posted 14 July 2009 - 06:36 PM

I am using dataset in some of my codes but I don't understand its purpose..

Can you tell me please?? :D
Was This Post Helpful? 0
  • +
  • -

#4 daxriders  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 25
  • Joined: 08-July 09

Re: Datagridview to textbox

Posted 15 July 2009 - 04:17 AM

I'm still a beginner in this matter and the experienced guys here can correct me but:

a dataset is a copy of your database in the computer's memory. It's purpose is to connect once, copy all the data(tables, queries,...) you need in the memory and then work with it as if you were connected to the database. Where you're done with all the changes on that data, you can then apply them to the "physical" database.

You can write all the code to use a dataset or have a typed dataset when you design it with the visual tool of the window "data source". It's advantage is that a lot of code is generated automatically and you can bind easily controls on your forms to it. Everytime you make a change on your dataset, the control is updated.

I guess you should read a good tutorial about ADO.NET and datasets before you start. :)
Google it!


View Posthuskyfritz, on 14 Jul, 2009 - 05:36 PM, said:

I am using dataset in some of my codes but I don't understand its purpose..

Can you tell me please?? :D

Was This Post Helpful? 0
  • +
  • -

#5 huskyfritz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 04-July 09

Re: Datagridview to textbox

Posted 15 July 2009 - 11:14 PM

Ah ok.. Do you know where to get ebooks for that??

^^/>




Was This Post Helpful? 0
  • +
  • -

#6 LoveIsNull  Icon User is offline

  • Recovering D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 646
  • Joined: 10-March 09

Re: Datagridview to textbox

Posted 15 July 2009 - 11:43 PM

Quote

Google it!

Was This Post Helpful? 0
  • +
  • -

#7 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: Datagridview to textbox

Posted 16 July 2009 - 09:44 AM

Hi,

The internet is the most usefull book you'll find and especially the MSDN library.

Look here!

This post has been edited by Luc001: 16 July 2009 - 09:44 AM

Was This Post Helpful? 0
  • +
  • -

#8 huskyfritz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 04-July 09

Re: Datagridview to textbox

Posted 16 July 2009 - 10:46 PM

Hi Luc001,

Thanks for your help. That library is a big help..

Cheers!
 :) 


Was This Post Helpful? 0
  • +
  • -

#9 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: Datagridview to textbox

Posted 16 July 2009 - 11:43 PM

Hi,

No problem, use the This post was Helpful button !
Was This Post Helpful? 1
  • +
  • -

#10 sidyusuf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 15-September 11

Re: Datagridview to textbox

Posted 11 October 2011 - 11:23 AM

View Posthuskyfritz, on 14 July 2009 - 01:47 AM, said:

Hi guys!

I am new in Vb.net and I am still studying this language.

I am trying to retrive data to a textbox from a datagridview.

I have Tabcontrol with two tabs naming Data Sheet View and Form View.
The datagridview is in Data Sheet view while my textboxes are in Form View.

Al I want is that everytime I click on the data in datagridview, it would display in textbox in form view.

Here are some of my code:

Dim ret As String = "select * from newstudent_tbl where USN='" & DataGridView1.SelectedCells(0).ToString & "'"
		cmd.CommandText = ret
		cmd.Connection = oConn
		oConn.Open()
		dr = cmd.ExecuteReader
		
		If dr.HasRows Then

			Do While dr.Read


				TextBox2.Text = dr(0)
				TextBox4.Text = dr(1)
				

			Loop

		End If
		oConn.Close()

		cmd.Dispose()
		oConn.Dispose()



Can you help me guys solve this problem??

thanks in advance!
:D



try this:

but it will display the data in second grid not in textbox
 Private Sub callgrid()
        Dim selectitem As String
        selectitem = dgv1.Item(1, dgv1.CurrentRow.Index).Value
        Dim ds As New DataSet
        Dim da = New sqlDataAdapter("ur query here ", con)
        da.fill(ds)
        dgv2.DataSource = ds.Tables(0)
 
    End Sub

    Private Sub dgv1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv1.CellDoubleClick
        callgrid()
    End Sub


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1