473,388 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

datagrid current record

How obtain the current record in the datagrid? The idea is doubleclick and
show another form with this current recor of my datagrid.

Thanks a lot
May 25 '06 #1
2 1240
Jose wrote:
How obtain the current record in the datagrid? The idea is doubleclick and
show another form with this current recor of my datagrid.

Thanks a lot

Use the underlying data source instead.

Tom
May 25 '06 #2
For starters, you need an easy way to reference what is currently
selected on the datagrid control. Start with something like this:
================================================== ============

Private Sub dgvBranches_CurrentCellChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles dgvBranches.CurrentCellChanged

Try
'Determine which row and column selected and
'display contents of cells in proper text boxes.
CurrentRow = dgvBranches.CurrentCell.RowNumber
CurrentColumn = dgvBranches.CurrentCell.ColumnNumber
ShowTheCells()

Catch ex As Exception
LogErrors(ex, " In frmMain_dgvBranches_CurrentCellChanged")
End Try

End Sub
================================================== =============

Once you have that settled then you can do things like passing values
into text boxes and such. There is a lot of formatting in this example
since I wanted to make sure that everything looked good and would save
in a consisten format in the database. Here is an example:

================================================== =============

Private Sub ShowTheCells()
'Use the cells from the selected row to display in the proper
text boxes

Try
dgvBranches.Select(CurrentRow)
txtState.CharacterCasing = CharacterCasing.Upper
txtBranchNum.Text = Trim(dgvBranches.Item(CurrentRow, 0))
txtBranchName.Text =
Trim(StrConv(dgvBranches.Item(CurrentRow, 1), VbStrConv.ProperCase))
txtRegCode.Text = Trim(dgvBranches.Item(CurrentRow, 2))
txtOrder.Text = Trim(dgvBranches.Item(CurrentRow, 3))
txtRegName.Text = RegionName(dgvBranches.Item(CurrentRow,
2))

If dgvBranches.Item(CurrentRow, 4) = "True" Then
cbxActive.Checked = True
ElseIf dgvBranches.Item(CurrentRow, 4) = "False" Then
cbxActive.Checked = False
End If

Dim i As Integer

For i = 0 To myDataSet.Tables("MySQL Branches").Rows.Count
- 1

If dgvBranches.Item(CurrentRow, 0) =
myDataSet.Tables("MySQL Branches").Rows(i).Item(0) Then
txtStreet.Text = StrConv(myDataSet.Tables("MySQL
Branches").Rows(i).Item(2), VbStrConv.ProperCase)
txtZip.Text = myDataSet.Tables("MySQL
Branches").Rows(i).Item(3)
txtCity.Text = StrConv(myDataSet.Tables("MySQL
Branches").Rows(i).Item(4), VbStrConv.ProperCase)
txtState.Text = StrConv(myDataSet.Tables("MySQL
Branches").Rows(i).Item(5), VbStrConv.UpperCase)
txtPhone.Text = myDataSet.Tables("MySQL
Branches").Rows(i).Item(6)
txtFax.Text = myDataSet.Tables("MySQL
Branches").Rows(i).Item(7)
txtConFirst.Text = StrConv(myDataSet.Tables("MySQL
Branches").Rows(i).Item(8), VbStrConv.ProperCase)
txtConLast.Text = StrConv(myDataSet.Tables("MySQL
Branches").Rows(i).Item(9), VbStrConv.ProperCase)
txtBranchEmail.Text =
StrConv(myDataSet.Tables("MySQL Branches").Rows(i).Item(10),
VbStrConv.UpperCase)
End If

Next

Catch ex As Exception
LogErrors(ex, " In ShowTheCells()")
End Try

End Sub

================================================== ==============

"tomb" does have a good point about using the underlying data though.
I think you would have to use the currency manager to accomplish that
one. Hope this helps.

Alan

May 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
2
by: Tom | last post by:
Hi, I have been through all kinds of documentation on the datagrid and dataviews. I have many expensive books that I have looked through. But nothing has really helped. I want to find out and...
1
by: Maqsood Ahmed | last post by:
Hello! There is a DataGrid on a form that is populated through DataTable and filters have been applied to through DataView. The DataTable gets updated through some events and obviously it also...
4
by: Glenn Owens | last post by:
I have a DataGrid web control which I've dynamically populated with template columns to be used for bulk-editting. Generally, all of the columns are textbox and/or dropdownlist child controls. ...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
3
by: danc | last post by:
I have a datagrid with a checkbox and dropdown list in each row. Both set AutoPostBack to true and ItemCommand and OnSelectedIndexChanged events for these controls works fine when DataGrid is not...
1
by: Jean-Claude Bertrand | last post by:
Hi! Windows of the application IO have to built (my first one in vb.Net) is made from 2 part: a) A grid wich will be used only to display the main information of the current record (so the...
2
by: Gene Hubert | last post by:
I'm assigning a new datasource (a datatable) to a datagrid that is aready displayed in a form. Then I assign a new value to CurrentRowIndex. The datagrid always scrolls so that the new current...
3
by: Brian Tkatch | last post by:
I have a form with two DataGrids, which are kept in sync manually via Stored PROCEDURE calls. That is, when a record is selected on the first grid, a stored PROCEDURE is CALLed to Fill() the next...
2
by: =?Utf-8?B?SnVsaWEgQg==?= | last post by:
Hi all Got a weird problem with pagination on a datagrid in asp.net 1.1. It's populated depending on user selected criteria (it either displays all or 1 record). It works fine in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.