Solved

Finding the control bound to a specific field in a DataTable

Posted on 2007-03-19
4
260 Views
Last Modified: 2013-11-07
Hi Experts,

I'm writing a VB.Net application and have the following problem.  I have a form with several textboxes on it.  I also have a DataTable on the form (Private dt as Data.DataTable).  The textboxes are bound to the datatable.  (Only the Text Properties).  

I do the binding like this: txtLastName.DataBindings.Add("Text", DataTableName, "LastName")

I need to add some information relating to the field being displayed by each textbox inside the tag of the textbox.  So in the example above, txtLastName.Tag will have some data that describes the LastName field.

My problem is: when the time comes to save and I detect that the LastName field has changed, I need to get the information stored inside the tag of txtLastName.  How can I find out what textbox is bound to the LastName field in the datatable?  I'll need a reference to that textbox so that I can get the tag.

I was hoping that the form's binding context, or maybe the datatable or maybe even the DataAdapter would have a method/property that can be used to easily determine this!  

I know that there several workarounds like looping through all the controls on the form or storing the required information inside the description property of the actual SQL Server field (which what I'm currently doing) but I'm really looking for the most effective way.  Looping through lots of controls inside lots of containers etc etc on a regular would be too slow.  Also, if I could retrieve the required info from within the exe itself and thereby doing away with all the database access to read the description properties it would be great!

Any ideas?

Thanks
0
Comment
Question by:PantoffelSlippers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 250 total points
ID: 18750353
I think you'll have to loop, but through the bindings collection of the bindingcontext rather than through the controls themselves would be most efficient.  Something like this

        Dim s As String = "<myFieldName>"
        For Each b As Binding In CType(BindingContext(<myTable>), CurrencyManager).Bindings
            Dim bo As BindingMemberInfo = b.BindingMemberInfo
            If bo.BindingField = s Then
                Debug.WriteLine(b.Control.Name)
                Exit For
            End If
        Next

Roger
0
 

Author Comment

by:PantoffelSlippers
ID: 18751266
Thanks Roger

I'll give that a shot.
0
 

Author Comment

by:PantoffelSlippers
ID: 18897454
Roger,

Havent tried yet.  On another project for now.  This is important - will report back soon.

Thanks
0
 

Author Comment

by:PantoffelSlippers
ID: 18999985
Thanks Roger

It works great!

Sorry about the long delay.

All the best and thanks again.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question