?
Solved

Load textbox from datagridview VB.net

Posted on 2011-09-23
9
Medium Priority
?
614 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 1000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

771 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