Referencing columns of current row

ckane55436

Member
Joined
Apr 12, 2007
Messages
8
Programming Experience
Beginner
I have a tableadapter, dataset and binding source. All is good, binding to datagrids and textboxes etc. However, I want to programically get data from a nondisplayed column of the current row to do some math and manipulation. I can not figure out how to do this.
 
The concept of "current row" is maintained by the binding source. To access it, do this:

VB.NET:
Private ReadOnly Property Current[B]YourDataTableName[/B]Row() As [B]YourDataSetName[/B].[B]YourDataTableName[/B]Row
 Get
   If [B]YourDataTableName[/B]BindingSource.Current Is Nothing Then Return Nothing
   Return DirectCast(DirectCast([B]YourDataTableName[/B]BindingSource.Current, DataRowView).Row, [B]YourDataSetName[/B].[B]YourDataTableName[/B]Row)
 End Get
End Property

at the top of your form..

Now anywhere on your form you can say

CurrentXXXRow and it will get you the current row the bindingsource is looking at

The items in bold are items you MUST change to be relevant to your project
 
I have a tableadapter, dataset and binding source. All is good, binding to datagrids and textboxes etc. However, I want to programically get data from a nondisplayed column

As an aside, you shouldnt really get data from displayed columns by saying Textbox1.Text..

Even if you want to get the data in a displayed column, use CurrentXXXRow.ThatColumnName rather than Textbox1.Text (presuming that that textbox is bound to that column)
 
Even if you want to get the data in a displayed column, use CurrentXXXRow.ThatColumnName rather than Textbox1.Text (presuming that that textbox is bound to that column)

uh-oh....can I ask why that is? I reference EVERYTHING by .text or .selectedvalue .... :(
 
How do i get the actual data in a field?

The data I want is not bound to any textbox. I now have the current row, how do I get a specfic value from a field?

New to .Net.
 
Error

DirectCast(DirectCast(EquipBindingSource.Current, DataRowView).Row, db4DataSet.EquipDataTable)

I get this error:

Error 1 Value of type 'System.Data.DataRow' cannot be converted to 'WindowsApplication1.db4DataSet.EquipDataTable'.
 
uh-oh....can I ask why that is? I reference EVERYTHING by .text or .selectedvalue .... :(

1) the control might not be displaying the data in the format in which it is stored, or anything remotely like that data that is stored

2) controls can only be accessed from the thread upon which they were created. in a multithreaded app, it might not be safe for a worker thread to access a control..
 
DirectCast(DirectCast(EquipBindingSource.Current, DataRowView).Row, db4DataSet.EquipDataTable)

I get this error:

Error 1 Value of type 'System.Data.DataRow' cannot be converted to 'WindowsApplication1.db4DataSet.EquipDataTable'.

EquipBindingSource is not bound to an object of type 'WindowsApplication1.db4DataSet.EquipDataTable'

You need to post more code if you want any further explanation.. The full project would be most helpful (zip it, but DO NOT INCLUDE the bin or obj folders in the zip)
 
I guess I just prefer getting the answers direct from the horse's mouth, rather than from the thing that got it from the horse's mouth! :)


In MVC architecture, we get data out of models, not so much out of views.. the textbox is the view to the model represented by the bindingsource
 
Back
Top