Roey Posted January 29, 2004 Posted January 29, 2004 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? Quote
AlexCode Posted January 29, 2004 Posted January 29, 2004 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 Quote Software bugs are impossible to detect by anybody except the end user.
Roey Posted January 29, 2004 Author Posted January 29, 2004 I am getting the following Cast error with that code: Option Strict On disallows implicit conversions from 'system.object' to 'system.data.datarow' Quote
Administrators PlausiblyDamp Posted January 29, 2004 Administrators Posted January 29, 2004 Dim DRow As DataRow DRow = directcast(me.BindingContext(DataView).Current,DataRow) 'Then just change the values DRow("ColumnName") = "BlaBla" Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Roey Posted January 29, 2004 Author Posted January 29, 2004 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. Quote
Administrators PlausiblyDamp Posted January 29, 2004 Administrators Posted January 29, 2004 Which line is giving the error then? That seems to be the only part casting between object and DataRow. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Roey Posted January 29, 2004 Author Posted January 29, 2004 (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 Quote
Administrators PlausiblyDamp Posted January 29, 2004 Administrators Posted January 29, 2004 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) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Roey Posted January 29, 2004 Author Posted January 29, 2004 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 Quote
Roey Posted January 29, 2004 Author Posted January 29, 2004 Sorry but another question for you. Why do you use DirectCast as oppossed to CType Thanks Quote
Administrators PlausiblyDamp Posted January 29, 2004 Administrators Posted January 29, 2004 http://www.xtremedotnettalk.com/showthread.php?s=&threadid=81759&highlight=ctype+directcast Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.