in2minds

hello

i need to map my datagridview row to a datarow, please help!!

here is my code:

Private Sub btnSeqUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeqUp.Click

If Not dgvEditList.SelectedRows.Count = 0 Then

Dim index As Integer = dgvEditList.SelectedRows(0).Index

If Not index = 0 Then

Dim row1 As DataRow = ( how do i map it to my Datagridview row here )

Dim row2 As DataRow = dv(index - 1).Row

row1("No") = CType(row1("No"), Integer) - 1

row2("No") = CType(row2("No"), Integer) + 1

dgvEditList.Refresh()

dgvEditList.Rows(index - 1).Selected = True

End If

End If

End Sub

Private Sub btnSeqDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeqDown.Click

If Not dgvEditList.SelectedRows.Count = 0 Then

Dim index As Integer = dgvEditList.SelectedRows(0).Index

If Not index = 0 Then

Dim row1 As DataRow = ( how do i map it to my Datagridview row here )

Dim row2 As DataRow = dv(index + 1).Row

row1("No") = CType(row1("No"), Integer) + 1

row2("No") = CType(row2("No"), Integer) - 1

dgvEditList.Refresh()

dgvEditList.Rows(index + 1).Selected = True

End If

End If

End Sub

thanks

MM



Re: Visual Basic General mapping datagridview to a datarow?

Rick

Dim row1 As DataRow = dgvEditList.Rows(index)





Re: Visual Basic General mapping datagridview to a datarow?

in2minds

hello

i had already tried this i get an error when i try that, "value of system.windows.forms.Datagridrow cannot be converted to system.data.datarow





Re: Visual Basic General mapping datagridview to a datarow?

Rick

my bad, try something like this:

Dim row1 As DataRow = Nothing

For Each dr As DataRow In dgvEditList.Rows

If dr Is dgvEditList.Rows(index) Then

row1 = dr

End If

Next





Re: Visual Basic General mapping datagridview to a datarow?

Swade

If you're using a binding source on your dataset, which is preferrable for a forms app, then do something like this:

Dim dr as dataset1.datatable1row

dr = Ctype(Ctype(bindingsource1.current, datarowview).row, dataset1.datatable1row)

If not using bindingsources, try:

dr = CType(dgvEditList.Rows(index), datarowview)






Re: Visual Basic General mapping datagridview to a datarow?

in2minds

hey rick,

tried your code get the same message "value of system.windows.forms.Datagridrow cannot be converted to system.data.datarow"

at line "For Each dr As DataRow In dgvEditList.Rows"

Thanks

MM





Re: Visual Basic General mapping datagridview to a datarow?

in2minds

hi swade,

I am getting my dgvEditList from a table i am not using binding. here is the code to fill the dgveditlist

dataresults = GetRecordings(sqlstatement)

dgvEditList.Rows.Clear()

Do While dataresults.Read()

Dim row0 As String() = {Clipnos, dataresults!EditNo, dataresults!PlayClip, dataresults!ClipIN, dataresults!ClipOUT, dataresults!DeleteClip, dataresults!Thumbnail, dataresults!RecordingID, dataresults!ClipInNo, dataresults!ClipOutNo}

With dgvEditList.Rows

.Add(row0)

End With

i cannot declare dr as dataset1.datatable1row

thanks

MM





Re: Visual Basic General mapping datagridview to a datarow?

Larry Charlton

Try something like:

Dim dgv As New DataGridView

For Each row As DataGridViewRow In dgv.Rows

Dim dr As DataRow = TryCast(row.DataBoundItem, DataRow)

Next

It should work as long as your bound to a datatable, probabbly not so well if you're bound to a list or array Smile






Re: Visual Basic General mapping datagridview to a datarow?

in2minds

hey larry,

how does your code fit in my code here

Private Sub btnSeqUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeqUp.Click

If Not dgvEditList.SelectedRows.Count = 0 Then

Dim index As Integer = dgvEditList.SelectedRows(0).Index

If Not index = 0 Then

Dim row1 As DataRow = ( how do i map it to my Datagridview row here )

Dim row2 As DataRow = dv(index - 1).Row

row1("No") = CType(row1("No"), Integer) - 1

row2("No") = CType(row2("No"), Integer) + 1

dgvEditList.Refresh()

dgvEditList.Rows(index - 1).Selected = True

End If

End If

End Sub

Thanks

MM





Re: Visual Basic General mapping datagridview to a datarow?

Larry Charlton

Something on the lines of:

If dgvEditList.SelectedRows.Count > 0 Then

Dim row1 As DataRow = TryCast(dgvEditList.SelectedRows(0).DataBoundItem, DataRow)

If row1 IsNot Nothing Then

Dim index As Integer = dgvEditList.SelectedRows(0).Index

row1("No") = CInt(row1("No")) - 1

dgvEditList.Refresh()

dgvEditList.Rows(index - 1).Selected = True

End If

End If