Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I have a windows form with comboboxes and textboxes bound to a DataView. Upon the click of a Button I want to modify values for the currently displayed record. How would I go about editing the values in a dataview programatically?
Posted

I think that if you use the BindingContext it'll do...

Like this:

dim DRow as DataRow
DRow = me.BindingContext(DataView).Current

'Then just change the values
DRow("ColumnName") = "BlaBla"

 

Alex :D

Software bugs are impossible to detect by anybody except the end user.
Posted

I am getting the following Cast error with that code:

 

Option Strict On disallows implicit conversions from 'system.object' to 'system.data.datarow'

Posted

I'm still getting a Cast error:

 

An unhandled exception of type 'System.InvalidCastException' occurred in elantis_UI.exe

 

Additional information: Specified cast is not valid.

Posted

(1) Dim dv As DataView

(2) dv = Me.dsCategory.Tables("Category").DefaultView

(3) Dim row As DataRow

(4) row = DirectCast(Me.BindingContext(dv).Current, DataRow)

 

Line 4

  • Administrators
Posted

Ahhhh, it returns a DataRowView not a DataRow so the following will compile (haven't checked to see what it does at runtime though....)

dv = Me.dsCategory.Tables("Category").DefaultView
	Dim row As DataRowView
	row = DirectCast(Me.BindingContext(dv).Current, DataRowView)

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Perfect, thanks for your help its only the second time that DataRow and DataRowView have caught me out. Maybe in a couple of years it will finally be implanted into my brain.

 

PS What does it say above Badger ???? Looks like wool

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...