Solved

Load textbox from datagridview VB.net

Posted on 2011-09-23
9
575 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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 …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 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