473,473 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VB 2005: Datagridview load new form with selected information

41 New Member
Hi,

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

Try
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)
connection.Open()
Dim command As New SqlCommand( _
"Select * from CustTracker", _
connection)
daCust.SelectCommand = command
Using daCust
daCust.Fill(ds, "Custs")
connection.Close()
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
DataGridView1.Columns.Add(CustID)

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

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
DataGridView1.Columns.Add(colCKNumber)
End Sub

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



Thank you very much for the help.
Apr 27 '07 #1
0 1280

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

Similar topics

1
by: Arvind | last post by:
Hi I edit a cell in a DataGridView, and then would move to another cell in the DataGridView using mouse. Then the DataGridView as of now does scroll down to the last visited cell. But when I try...
1
by: RSH | last post by:
Hi, I have a situation where I have a DDL that lists all of the tables in a particular database, and a Datagridview which appears in the same from below the DDL.. When the user selects a new...
2
by: Lennart | last post by:
Hi I have a DataGridView on a Form filled with data from a DataTable. When I Load this form I want to select a row in the DataGridView depending on a selected Primary Key index; How do I do...
3
by: =?Utf-8?B?Sm9obiBCdW5keQ==?= | last post by:
New to databinding in vs2005, I always did it manually in 2003. I have no problem loading comboboxes, and a change in that combobox changes the data in the textboxes but I can not figure out a way...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
3
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I'm trying to add a datagridview control to a Windows Form to display read-only information in visual basic 2005. My understanding is that datareader will be faster for this purpose. I have the...
1
by: TG | last post by:
Hi! I have an application in which I have some checkboxes and depending which ones are checked those columns will show in the datagridview from sql server or no. After that I have 2 buttons:...
4
by: thesti | last post by:
hello, how to make a datagridview to select no row after i bind it datasource to a datatable. i have this code in my form load myDGView.DataSource = myDataTable then when the form load,...
1
by: Avedo | last post by:
Hello! I have a form application with a DataGridView, and an Save/Delete and Cancel button. When the application is opened, it is supplied an XML file that may or may not exist, and display the...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.