Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 18th, 2004, 07:22 AM
Authorized User
 
Join Date: Jun 2004
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?

 
Old June 18th, 2004, 07:38 AM
Friend of Wrox
 
Join Date: Jul 2003
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

 
Old June 18th, 2004, 07:41 AM
Authorized User
 
Join Date: Jun 2004
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

 
Old June 18th, 2004, 07:54 AM
Authorized User
 
Join Date: Jun 2004
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

 
Old June 18th, 2004, 08:02 AM
Friend of Wrox
 
Join Date: Jul 2003
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

 
Old June 18th, 2004, 08:16 AM
Authorized User
 
Join Date: Jun 2004
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

 
Old June 18th, 2004, 08:21 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Are you using a dataset for your data source?

 
Old June 18th, 2004, 08:24 AM
Authorized User
 
Join Date: Jun 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes a dataset called dataset1

 
Old June 18th, 2004, 08:30 AM
Friend of Wrox
 
Join Date: Jul 2003
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)



 
Old June 18th, 2004, 08:38 AM
Authorized User
 
Join Date: Jun 2004
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






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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.