Solved

Load textbox from datagridview VB.net

Posted on 2011-09-23
9
560 Views
Last Modified: 2012-08-14
I am populating a datagridview from a text file.  (which is a temp view and loaded on demand)  I am populating 4 columns based off of the info on the text file.  Customer, type, name, address (I can paste code if needed but didnt think it was critial.)

Users will select a row from datagrid view.  I want to pass selected row info from the datagridview to 4 separate text boxes.  The user will fill in addional textboxes and then click a "SAVE" button that will write to a SQL DB.

I think this is easy but am lost since this is just pulling info from the datagridview and not a bound SQL dataset.

Thanks
0
Comment
Question by:rommelit
  • 3
  • 3
  • 3
9 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 36587506
how will the users be selecting the rows? By clicking onthe row header or have you implemented a checkbox in the row header?
0
 

Author Comment

by:rommelit
ID: 36587561
Clicking on the row but I am open to suggestions on ways to improve.
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 250 total points
ID: 36587639
you can use the Cell_Click event and get the values from the currentrow
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    If e.ColumnIndex = -1 Then
        Dim xRow = Me.DataGridView1.CurrentRow
        Dim TextB1 = xRow.Cells("Customer")
        Dim TextB2 = xRow.Cells("type")
        Dim TextB3 = xRow.Cells("Name")
        Dim TextB4 = xRow.Cells("Address")
    End If
End Sub

Open in new window

0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 17

Expert Comment

by:nepaluz
ID: 36587661
I have assumed above that your datagridview is named DataGridView1.
As with regard to the other modes of selection, just get up and running with what you have at the moment, and the UI tweaks, (though extremely important!) can come later,
0
 
LVL 15

Expert Comment

by:x77
ID: 36588019
nepaluz - is correct except for it is referencing cells, not getting values.

1   Textbox1.Text = xRow.Cells("Customer").Value.ToString
2   Textbox1.Text = xRow.Cells("Customer").FormattedValue.ToString

Option 2 - Recomended.
Note that a cell can contains date or number and you wants on textbox the formated value.
0
 

Author Comment

by:rommelit
ID: 36588072
Yes.  I am just using a scratch app to test before dropping into final app.  However, the code is not generating any change after clicking the cells.  Do I need to set the textbox.text value equal to the dimensioned value you gave?
0
 
LVL 15

Assisted Solution

by:x77
x77 earned 250 total points
ID: 36588131
You can remove the
   If e.ColumnIndex = -1 Then
   End if

Note that sugest click on Header row.
If you wants click on any cell or header row then code:

   If e.RowIndex >= 0 Then ' Avoid Header Row
      Textbox1.Text = xRow.Cells("Customer").FormattedValue.ToString
      ...  
 
   End if

Note that you can use Index on cells
    Textbox1.Text = xRow.Cells(0).FormattedValue.ToString

also you can code:
     Dim xRow = Me.DataGridView1.rows(e.RowIndex)
0
 

Author Comment

by:rommelit
ID: 36588141
Thanks guys!
0
 
LVL 15

Expert Comment

by:x77
ID: 36588155
Sorry, I use Term "Header Row" also for Row Selector.

nepaluz Suggest Click on Row-Selector:   If e.ColumnIndex = -1 Then
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now