DataGrid Trouble / Help

M

Miro

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.CurrentCell.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
 
Y

yuichiro ochifuji

Hi,Miro

in message
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.CurrentCell.RowIndex)("StaffID")

directcast(Me.StaffDataGridView.CurrentRow.DataBoundItem,
DataRowView).Row.Item("StaffID")
 
M

Miro

yuichiro said:
Hi,Miro

in message


You can't set String to Integer,so
Dim iStaffMembeer as Integer=-1


directcast(Me.StaffDataGridView.CurrentRow.DataBoundItem,
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.StaffDataGridView.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top