How can i find out if a control is databound

M

Martin P

Hi all

Firstly, sincere apologies for cross posting this, I did post on the
DataBinding forum but the traffic there is very low so I'm not
confident of a reply.

Anyway, I'm trying to put together a method to loop through all
controls on a
form and see if any of them are databound.


For simple binding this seems to be straight forward enough (by
checking the control.Bindings collection as in the example below),
but
this doesn't work for combo boxes or datagridviews (and probably
numerous other items).


Does anyone know how I can check any type of control to establish
whether it's bound or not - whether it's simple or complex binding?


Thanks a lot in advance
Martin


Code snippet to check for simple binding - this would be called for
each control on a form:


'================
Public Sub GetBoundControls(ByVal caller As Control)
Dim ctl As Control
For Each ctl In caller.Controls
If ctl.DataBindings.Count > 0 Then
' do some work here
End If
Next
End Sub
'================
 
B

Bob Powell [MVP]

You can check the DataSource property of the control to see if it's null. if
it's not null it's databound.

You can look at the binding managers to see if they are based on
CurrencyManager (complex binding) or PropertyManager (simple binding).

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
M

Martin P

You can check the DataSource property of the control to see if it's null. if
it's not null it's databound.

You can look at the binding managers to see if they are based on
CurrencyManager (complex binding) or PropertyManager (simple binding).

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consultinghttp://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Trickshttp://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQhttp://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.













- Show quoted text -

Thanks Bob - I'll take a look at those tonight/this weekend
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top