Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 18th, 2004, 07:22 AM
Authorized User
 
Join Date: Jun 2004
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default populating a text field

hi guys im trying to populate some text fields by double clicking on a row in my data grid.

any ideas?

Reply With Quote
  #2 (permalink)  
Old June 18th, 2004, 07:38 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: York, , United Kingdom.
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

In the Datagrid.DoubleClick event, you could use the CurrentCell property, if you wanted the contents of the currently selected cell to be copied into a textbox:

Code:
Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick
  Dim cell As DataGridCell = DataGrid1.CurrentCell
  Dim text As String = Dataset1.Rows(cell.RowNumber)(cell.ColumnNumber).ToString
  textbox1.text = text
End Sub
This might need a bit of tweaking as I haven't tested it, but should work

Reply With Quote
  #3 (permalink)  
Old June 18th, 2004, 07:41 AM
Authorized User
 
Join Date: Jun 2004
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for that but what if i had more then 1 text box, i mean in my situation i have 8 text boxes that need to filled up by the 8 columns in the data grid

Reply With Quote
  #4 (permalink)  
Old June 18th, 2004, 07:54 AM
Authorized User
 
Join Date: Jun 2004
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

just tryied tht code out u gave me everything looks good, but i get a error datasetname.Rows, it tells me that Rows is not a member of system.data.dataset

Reply With Quote
  #5 (permalink)  
Old June 18th, 2004, 08:02 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: York, , United Kingdom.
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I presume you're using a dataset to populate your datagrid? You have to refer to your dataset where I've put Dataset1

If you are using a dataset, you do the following (you also need to know what table you're displaying in the datagrid; the name of this table goes in instead of {MyTable}):

Dim cell As DataGridCell = DataGrid1.CurrentCell
Dim ds As Dataset = Datagrid1.DataSource

' get a handle on the row just clicked on...
Dim dr As Datarow = ds.Tables("{MyTable}").Rows(cell.RowNumber)

' populate text boxes...
textbox1.text = dr(0)
textbox2.text = dr(1)
textbox3.text = dr(2) ' and so ad nauseum...

As before, all this goes in your double click event handler

Reply With Quote
  #6 (permalink)  
Old June 18th, 2004, 08:16 AM
Authorized User
 
Join Date: Jun 2004
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok just tried out ure last code, i get a error when i run the program it says 'specified cast is not valid', when i debug it, its refering to ure line in the code where it says Dim ds As Dataset = Datagrid1.DataSource.


i presume ds stands for the name of my dataset

Reply With Quote
  #7 (permalink)  
Old June 18th, 2004, 08:21 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: York, , United Kingdom.
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Are you using a dataset for your data source?

Reply With Quote
  #8 (permalink)  
Old June 18th, 2004, 08:24 AM
Authorized User
 
Join Date: Jun 2004
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes a dataset called dataset1

Reply With Quote
  #9 (permalink)  
Old June 18th, 2004, 08:30 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: York, , United Kingdom.
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

ds doesn't stand for the name of your dataset - it was a new dataset I was defining.

Instead of using ds in my example, use your dataset. Don't bother with the Dim ds as Dataset = datagrid1.datasource at all. To make it work, you'd need to do Dim ds as Dataset = CType(datagrid1.datasource, Dataset)



Reply With Quote
  #10 (permalink)  
Old June 18th, 2004, 08:38 AM
Authorized User
 
Join Date: Jun 2004
Location: , , .
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok ive just got it working but it only gets the first cell information of the selected row, ie, in my row i have
name, surname and address. the following code only gets name into my text field. I have 3 text fields set up.

Dim cell As DataGridCell = DataGrid1.CurrentCell
Dim text As String = Dataset1.tables(''employee'').Rows(cell.RowNumber) (cell.ColumnNumber).ToString
textbox1.text = text
textbox2.text = text
textbox3.text = text

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
populating a listbox with a field contains comma bjcountry Access 3 February 17th, 2016 05:07 PM
populating drop down through text field nasirmunir Javascript How-To 5 June 30th, 2008 11:01 AM
A form field list populating based on another fiel ebburks Access 2 June 3rd, 2006 09:37 AM
Populating field Popper Javascript How-To 10 September 23rd, 2004 06:06 PM
Automate adding record and populating field bmurrin Access 3 January 29th, 2004 12:25 PM



All times are GMT -4. The time now is 10:16 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.