Solved

Load textbox from datagridview VB.net

Posted on 2011-09-23
9
594 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

737 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