Hi,
I'm currently working on a function which reads an xml file and automatically checks whether the information in this file may be used or not. If it finds a row which cannot be used it will automatically replace this row by a default row which is hardcoded into the program.
My problem is, that I don't want to put the color codes as strings into my DataTable but convert them to actual Colors right away. This succeeds but when I try to cast the color out of the DataTable it fails and I don't see why because I have seen this in several examples.
The program does the following:
String -> Hex -> Color -> Save into DataTable -> Cast as Color
and the last step fails. Does anyone know why and how I can fix this?
best regards
Cyclonit
5 3782
show the code where the error occur
I'm doing the following to write the color into the DataTable: - String colorHex = (String)fileRow.ItemArray[3];
-
colorHex = colorHex.TrimStart('#');
-
-
Int32 R = Int32.Parse(colorHex.Substring(0, 2), NumberStyles.AllowHexSpecifier);
-
Int32 G = Int32.Parse(colorHex.Substring(2, 2), NumberStyles.AllowHexSpecifier);
-
Int32 B = Int32.Parse(colorHex.Substring(4, 2), NumberStyles.AllowHexSpecifier);
-
-
Color color = Color.FromArgb(255, R, G, B);
-
Object colorObj = color;
-
-
tempDesign.Rows.Add((String)fileRow.ItemArray[0], (String)fileRow.ItemArray[1], (String)fileRow.ItemArray[2], colorObj);
When I check how the entry looks like in the DataTable (via "run to cursor") VisualStudio shows it like this: - colorObj = "{Name=ffff00aa, ARGB=(255, 255, 0, 170)}"
My code to extract it (not final, just for debugging) is: - Object colorObj = SMDesign.Design.Rows[0].ItemArray[3];
-
Color color = (Color)colorObj;
And VisualStudio shows the object this way: - colorObj = "Color [A=255, R=255, G=0, B=170]"
well, I have tried storing and retrieving color value in and from a DataTable with the following code: - DataTable dt = new DataTable();
-
dt.Columns.Add("color", typeof(Color));
-
dt.Rows.Add(Color.FromArgb(255,123,132,132));
-
dt.Rows.Add(Color.Red);
-
dt.Rows.Add(Color.FromName("yellow"));
-
Color a = (Color)dt.Rows[0][0];
-
Color b = (Color)dt.Rows[1][0];
-
Color c = (Color)dt.Rows[2][0];
Is this solve your problem?
Hi, you are welcome. perhaps, you may consider to mark "choose as best answer button" on the most appropriate post that has solved your problems. :-)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Pankaj Jain |
last post by:
Hi All,
I have a class A which is derived from ServicesComponent to participate in automatic transaction with falg Transaction.Required. Class A is exposed to client through remoting on Http...
|
by: hrhoe |
last post by:
Hi,
I'm trying to create a reusable component with C#.
So, I created a user control that uses Microsoft SQLDMO
Object Library (SQLDMO).
And I could add that UserControl on Toolbox.
However,...
|
by: Imran Aziz |
last post by:
Hello All,
I am getting the following error on our production server, and I dont
get the same error on the development box.
Unable to cast object of type 'System.Byte' to type 'System.String'.
...
|
by: |
last post by:
I have the following class :
Public Class MyTreeNode
Inherits TreeNode
Dim mystring As String
End Class
Now, when I try to do this :
''''''''''''nodes is a TreeNodeCollection, s is string
|
by: sam |
last post by:
Hi:
I am not sure if this is the right place to post this question. Please let
me know if it is not and I appreciate if someone could point me in the right
direction.
I am getting this error...
|
by: Optimus |
last post by:
Hi everyone,
I currently develop an application in vs.net 2005 with vb.net.
I was trying to use typed dataset and I've got in trouble for
converting untyped dataset
into Typed DataSet. I don't...
|
by: hlyall1189 |
last post by:
Hi,
I recently started upgrading some of my old vs 2003 apps to vs 2005 and
used the conversion tool but now i get the following error after
building the page. I have typecasted the lines as...
|
by: keithb |
last post by:
What could be causing this?
this code:
String Com = "";
if (Com != (String)rw.ItemArray)
fails at runtime with the error message: Unable to cast object of type
'System.Int32' to type...
|
by: Jim in Arizona |
last post by:
I get this error:
Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlInputText'
to type 'System.Web.UI.WebControls.TextBox'.
Using this code:
Dim test3 As TextBox
test3 =...
|
by: =?Utf-8?B?U2NvdHQ=?= |
last post by:
Hello,
Using VS2008 in a C# web service application, a class has been created that
inherits from the ConfigurationSelection. This class file has been placed in
the App_Code folder. The...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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: 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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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,...
| |