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. :) ) -
Private Sub btnButton3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnButton3.Click
-
Dim conString = ConfigurationManager.ConnectionStrings("conStringDFRE")
-
Dim con As New SqlConnection(conString.ConnectionString)
-
-
Dim dsProperties As New DataSet
-
Dim sdaProperties As New SqlDataAdapter("SELECT Name, Value FROM tbl_Control_Records", con)
-
-
sdaProperties.Fill(dsProperties, "tbl_Control_Records")
-
-
con.Close()
-
-
Dim Name As String
-
Dim Value As String
-
-
'BackColor
-
Name = dsProperties.Tables(0).Rows(0).ItemArray(0)
-
'DarkBlue
-
Value = dsProperties.Tables(0).Rows(0).ItemArray(1)
-
-
'MsgBox("Name: " & Name & vbCrLf & "Value: " & Value)
-
'txtTextBox1.BackColor = DarkBlue
-
-
'This does not work
-
CallByName(txtTextBox1, Name, CallType.Set, Value)
-
'This works!
-
CallByName(txtTextBox1, Name, CallType.Set, DarkBlue)
-
-
-
End Sub
-
5 2191
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! -
'Doesn't work
-
txtTextBox1.GetType().GetProperty(Name).SetValue(txtTextBox1, Value, Nothing)
-
'Works
-
txtTextBox1.GetType().GetProperty(Name).SetValue(txtTextBox1, DarkBlue, Nothing)
-
The Color.FromName method of the System.Drawing namespace let's create a color structure from a string.
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.
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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.
...
|
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...
|
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...
|
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...
|
by: cwertman |
last post by:
I have a question regarding dynamic properties.
I have an Object say
Account
--Id
--Prefix
--Fname
--Lname
--Suffix
|
by: cwertman |
last post by:
I have a question regarding dynamic properties.
I have an Object say
Account
--Id
--Prefix
--Fname
--Lname
--Suffix
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
| |