473,406 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Dynamic properties via CallByName

aas4mis
97
Is it possible to assign control properties from a SQL Server table? This is the closest i've been able to come. It errors out due to the fact i'm passing a string and not the correct property type. Any way to implicitly convert the string to the correct property type? Possibly be getting the correct type from the "Name" value? Just thinking out loud.

As always, thanks to the scripts community for your help (I mean bytes. :) )

Expand|Select|Wrap|Line Numbers
  1.     Private Sub btnButton3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnButton3.Click
  2.         Dim conString = ConfigurationManager.ConnectionStrings("conStringDFRE")
  3.         Dim con As New SqlConnection(conString.ConnectionString)
  4.  
  5.         Dim dsProperties As New DataSet
  6.         Dim sdaProperties As New SqlDataAdapter("SELECT Name, Value FROM tbl_Control_Records", con)
  7.  
  8.         sdaProperties.Fill(dsProperties, "tbl_Control_Records")
  9.  
  10.         con.Close()
  11.  
  12.         Dim Name As String
  13.         Dim Value As String
  14.  
  15.         'BackColor
  16.         Name = dsProperties.Tables(0).Rows(0).ItemArray(0)
  17.         'DarkBlue
  18.         Value = dsProperties.Tables(0).Rows(0).ItemArray(1)
  19.  
  20.         'MsgBox("Name: " & Name & vbCrLf & "Value: " & Value)
  21.         'txtTextBox1.BackColor = DarkBlue
  22.  
  23.         'This does not work
  24.          CallByName(txtTextBox1, Name, CallType.Set, Value)
  25.         'This works!
  26.          CallByName(txtTextBox1, Name, CallType.Set, DarkBlue)
  27.  
  28.  
  29.     End Sub
  30.  
Jan 6 '12 #1
5 2191
aas4mis
97
I've also tried the following. Same issue, need to get property type and cast before inserting "Value".

Any words of wisdom would be appreciated. Thanks!

Expand|Select|Wrap|Line Numbers
  1.         'Doesn't work
  2.         txtTextBox1.GetType().GetProperty(Name).SetValue(txtTextBox1, Value, Nothing)
  3.         'Works
  4.         txtTextBox1.GetType().GetProperty(Name).SetValue(txtTextBox1, DarkBlue, Nothing)
  5.  
Jan 6 '12 #2
Rabbit
12,516 Expert Mod 8TB
The Color.FromName method of the System.Drawing namespace let's create a color structure from a string.
Jan 7 '12 #3
aas4mis
97
Thanks Rabbit, I'm not at my work pc at the moment. Do most objects have a FromName method? My sql table will be feeding a lot of properties if so.
Jan 9 '12 #4
Rabbit
12,516 Expert Mod 8TB
I'm not sure if all of the objects have it. I just looked up the structure on the online documentation and browsed the methods that were available.
Jan 9 '12 #5
Frinavale
9,735 Expert Mod 8TB
What does the CallByName method do??

You need to set the value with the right Type.
If you are setting the Foreground of the TextBox, then you need to supply the Foreground property with the correct type (a Color).

This means that you have to know what type of object needs to be created to set the property and you need to populate that object with the value stored in the database.

-Frinny
Jan 9 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Leon Jollans | last post by:
Hi all Is there a way to catch all property requests and resolve at runtime internally within the class? I ask because I'm looking into creating a dynamic CrystalReport web service, and all the...
2
by: listerofsmeg | last post by:
Newbie here. I want to use a .config file with my simple console app, but no matter what I do I cannot get the "dynamic" rollout in my properties window. In the end I gave up and coded the...
3
by: Guy Harwood | last post by:
Hi, I have designed a textbox that inherits from the System.Windows.Forms.Textbox control. when the control is readonly the back color changes to a light blue to indicate that it is frozen. ...
4
by: Richard Abraham | last post by:
I have created a new class ServiceTimer based upon the .NET System.Timers.Timer class. This has a new property CollectionIntervalMinutes which I expected to be added to the 'Behavior' section of the...
1
by: jm | last post by:
I am using (trying) dynamic properties to store a database connection. However, I don't have a connection object on the form. I just do a OdbcConnection in my code. So I can't use the VS IDE to...
1
by: davidw | last post by:
I found it seems there is a way to create a class with dynamic properties, I don't really need define each property? In ASP.NET, Profile is created with all profile items in web.config as its...
3
by: cwertman | last post by:
I have a question regarding dynamic properties. I have an Object say Account --Id --Prefix --Fname --Lname --Suffix
5
by: cwertman | last post by:
I have a question regarding dynamic properties. I have an Object say Account --Id --Prefix --Fname --Lname --Suffix
0
by: vnu | last post by:
Hi, Hi, I am working in .net emvironment using vs2005 and vb.net as the language. In one of my project, I need to display the properties of a com object which has dynamic properties(late bind...
0
by: Rahul | last post by:
Friends, My Question is related to the DTS Package (Dynamic Properties Task). I have a DTS package, In this, I transfer data from a database to another database. Senario -: (DB1.tbl1...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.