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

DataGrid Trouble / Help

P: n/a
VB 2005 express...

I created a database "Staff" and it has 1 table in it.
There are 3 columns in it so far.
"StaffID" -INT - Primary Key auto incremented by 1
"FirstName" - Varchar
"LastName" - varchar
( there will be more later - but baby steps )

Then I created 2 forms.
Form1 is the main form where I dragged the datagrid to the form.

Now I made the Datagrid.SelectionMode = FullRowSelect
and the datagrid is not editable.

Now On Form2 I created a property that is going to store the "StaffID"
This form I am going to try to code all "without a wizard".

====
Dim iStaffMember As Integer = ""

Public Property StaffMember() As Integer
Get
Return iStaffMember
End Get
Set(ByVal Value As Integer)
iStaffMember = Value
End Set
End Property
===

So now back on Form1 right before I try to "Form2.SHOW()" I try to set
that property from the datagrid so i can do my "own select" statement in
form 2 to show the detail's of the data.
( Example like: Select * from Staff where StaffID = StaffMemberProperty )

But I just cant seem to get the property set correctly

Dim fStaffMember as New Form2
fStaffMember.StaffMember =
Me.StaffDataSet.Staff.Rows(Me.StaffDataGridView.Cu rrentCell.RowIndex)("StaffID")

first off, the CurrentCell.RowIndex is incorrect - since I allow
resorting by column, its actually not the correct index from the dataset.

2nd, I get a convert error.

What is the parameter I should be using to get the "row#" from the bound
dataset?
And what Datatype should by Property be dim'd as?

Thanks

Miro
Oct 8 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,Miro

"Miro" wrote in message
news:uM*************@TK2MSFTNGP06.phx.gbl
Dim iStaffMember As Integer = ""
You can't set String to Integer,so
Dim iStaffMembeer as Integer=-1
Dim fStaffMember as New Form2
fStaffMember.StaffMember =
Me.StaffDataSet.Staff.Rows(Me.StaffDataGridView.Cu rrentCell.RowIndex)("StaffID")
directcast(Me.StaffDataGridView.CurrentRow.DataBou ndItem,
DataRowView).Row.Item("StaffID")

Oct 9 '07 #2

P: n/a
yuichiro ochifuji wrote:
Hi,Miro

"Miro" wrote in message
news:uM*************@TK2MSFTNGP06.phx.gbl
>Dim iStaffMember As Integer = ""

You can't set String to Integer,so
Dim iStaffMembeer as Integer=-1
>Dim fStaffMember as New Form2
fStaffMember.StaffMember =
Me.StaffDataSet.Staff.Rows(Me.StaffDataGridView.C urrentCell.RowIndex)("StaffID")

directcast(Me.StaffDataGridView.CurrentRow.DataBou ndItem,
DataRowView).Row.Item("StaffID")
I have just figured this out, just as you posted your post for me,

Dim bmStaff As BindingManagerBase =
Me.StaffDataGridView.BindingContext(Me.StaffDataGr idView.DataSource,
Me.StaffDataGridView.DataMember)
Dim dr As DataRow = CType(bmStaff.Current, DataRowView).Row

frmMain.fStaffMember.StaffMember = CInt(dr("StaffID"))

I tried yours and had to put a CInt( around your directcast.

Im assuming both our codes are doing the same thing?

Thanks,

Miro
Oct 9 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.