changing the value of a text box

based on a datagrid view row

Page 1 of 1

4 Replies - 2322 Views - Last Post: 20 July 2011 - 04:59 AM Rate Topic: -----

#1 MrWobbles  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 31
  • View blog
  • Posts: 328
  • Joined: 11-April 08

changing the value of a text box

Post icon  Posted 05 August 2008 - 10:32 AM

Private Sub fillTextBoxes()
		Dim columnX As DataGridViewColumn
		Dim rowX As DataGridViewRow

		For Each columnX In dgView.Columns

			rowX = dgView.CurrentRow

			Me.Controls.Item(columnX.Name).Text = rowX.Cells(columnX.Name).Value.ToString

		Next
	End Sub


What I am trying to do is change the value of textboxes that were created based on the fields in a database that also
supplies the datagridview. The column name and the names of the text boxes are the same. My text boxes are nested in a tab page, a split container and a group box (allows the user to move the controls around on the form via another class) the datagrid view is also nested in a tab, and a second panel. What I want to do is when the user selects on cell from one row the text boxes fill with the contents from that row. The datagridview itself will also be editable, but the text boxes are there so the user can more easily see which data they are dealing with. I have looked quite a bit for a solution to this, but with the code I have currently I get the following error:

Object reference not set to an instance of an object.

on line 9.

~Mr.Wobbles

Is This A Good Question/Topic? 0
  • +

Replies To: changing the value of a text box

#2 MrWobbles  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 31
  • View blog
  • Posts: 328
  • Joined: 11-April 08

Re: changing the value of a text box

Posted 06 August 2008 - 09:56 AM

While looking through the sticky's in this forum, i realized that I am in fact using vb.net, however I figured that there wouldn't be much difference so I will go ahead and post what I figured out to this problem here, and direct all future questions to the .NET forum.

While I feel like I am bludgeoning the problem this is the solution I found:

Private Sub fillTextBoxes()
		Dim columnX As DataGridViewColumn
		Dim rowX As DataGridViewRow
		Dim i As Integer = 0

		While i < Me.portTabs.SelectedTab.Controls.Item(0).Controls.Item(0).Controls.Count
			For Each columnX In dgView.Columns
				rowX = dgView.CurrentRow

				If Me.portTabs.SelectedTab.Controls.Item(0).Controls.Item(0).Controls.Item(i).Name = columnX.Name Then
					Me.portTabs.SelectedTab.Controls.Item(0).Controls.Item(0).Controls.Item(i).Controls.Item(0).Text = rowX.Cells(columnX.Name).Value.ToString
					Exit For
				End If

			Next
			i = i + 1
		End While
	End Sub



If you can see a more elegant way of accomplishing the same thing, then I am all ears.

By the way - portTabs is my tab page holder, the first Controls.Item(o) would be the split container, the next is the
first panel, then the group box (has the name) and finally I change the value of the text box within the if statement because for some odd reason every other value returned from the expression is the tab page name... or something else that is not actually in the panel.

Any other questions that anyone may have I will be happy to answer.
Was This Post Helpful? 0
  • +
  • -

#3 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 415
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: changing the value of a text box

Posted 06 August 2008 - 10:57 AM

Moved to VB.NET.
Was This Post Helpful? 0
  • +
  • -

#4 fachagooch  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 10-March 10

Re: changing the value of a text box

Posted 20 July 2011 - 03:05 AM

I am stuck on this same issue, did you ever resolve this?
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5669
  • View blog
  • Posts: 22,517
  • Joined: 23-August 08

Re: changing the value of a text box

Posted 20 July 2011 - 04:59 AM

fachagooch, please open a new topic and include a complete description of your problem, along with YOUR code, in code tags.

Closed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1