Solved

Load textbox from datagridview VB.net

Posted on 2011-09-23
9
527 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

18 Experts available now in Live!

Get 1:1 Help Now