Solved

Finding the control bound to a specific field in a DataTable

Posted on 2007-03-19
4
262 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
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…

630 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