By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,101 Members | 1,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,101 IT Pros & Developers. It's quick & easy.

VB 2005: Datagridview load new form with selected information

P: 41

This is my first big project. I have a form that is loaded with customer information. The datagrid is created with code as you can see below. I do not want the user to be able to update data in the gridview, for fear of mistakes.

I have a second form with textboxes. How can I load the second form textboxes with the information that was selected in this gridview. I did make one field a hyperlink field and can actually load the form, but my selection does not show up in the textboxes.

Here is the code..... :

Private Function LoadDS() As DataSet

Dim connectStringBuilder As New SqlConnectionStringBuilder()
connectStringBuilder.DataSource = My.Settings.Server
connectStringBuilder.InitialCatalog = My.Settings.Database
connectStringBuilder.UserID = My.Settings.User
connectStringBuilder.Password = My.Settings.Password
Using connection As New SqlConnection(connectStringBuilder.ConnectionStrin g)
Dim command As New SqlCommand( _
"Select * from CustTracker", _
daCust.SelectCommand = command
Using daCust
daCust.Fill(ds, "Custs")
End Using
End Using
Return ds
Catch err As SqlException
MessageBox.Show(err.Message, "SQL Exception", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return Nothing
End Try
End Function

Private Sub SetupGrid()
DataGridView1.AlternatingRowsDefaultCellStyle.Back Color = SystemColors.InactiveCaptionText
DataGridView1.AutoGenerateColumns = False
DataGridView1.DataSource = CustBindS
DataGridView1.MultiSelect = False
DataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect
DataGridView1.VirtualMode = True
Dim CustID As New DataGridViewTextBoxColumn()
CustID.DataPropertyName = "ID"
CustID.HeaderText = "ID"
CustID.Name = "ID"
CustID.ReadOnly = True
CustID.Visible = True

Dim ITPrice As New DataGridViewTextBoxColumn()
ITPrice.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
ITPrice.DataPropertyName = "ItemPrice"
ITPrice.HeaderText = "Item Price"
ITPrice.Name = "ItemPrice"
ITPrice.ReadOnly = False

Dim colCKNumber As New DataGridViewLinkColumn()
colCKNumber.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
colCKNumber.MinimumWidth = 100
colCKNumber.DataPropertyName = "CheckNumber"
colCKNumber.HeaderText = "Check Number"
colCKNumber.LinkBehavior = LinkBehavior.AlwaysUnderline
colCKNumber.LinkBehavior = LinkBehavior.SystemDefault
colCKNumber.LinkColor = Color.Blue
colCKNumber.Name = "CheckNumber"
colCKNumber.SortMode = DataGridViewColumnSortMode.Automatic
End Sub

Private Sub Modify2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataS = LoadDS()
If DataS IsNot Nothing Then
CustBindS = New BindingSource(DataS, "Custs")
End If
End Sub

Thank you very much for the help.
Apr 27 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.