|
How to I convert System.Drawing.KnownColor.{item} to a System.Color color. My one attempt at using ColorConverter raised a very nice object exception. Anyone know?
Thx.
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|
|
Since KnownColor is an enum, you can't use the ColorConverter class on it. Just use the Color class' .FromKnownColor() static method to create the color object:
Color someColor = Color.FromKnownColor(KnownColor.whatever);
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Doh! I never noticed that method under Color. It worked, thanks much.
Michael
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|
|
I have a treeview control. I was able to generate the tree nodes for this treeview control by reading the structure of the tree from a database table. At each treenode, I show a check box (CheckBoxes is true). On the Sql Server Side, I have a table which has the following structure:
TreeStruct (NodeID int, NodeDesc varchar(50), NodeState tinyint)
This table is pre populated with information in the order in which the tree will be constructed.
I want to be able to do the following:
(a) whenever the CheckState property changes (i.e., a user Checks/Unchecks a node, I want to commit the change to the database
(b) Let the user make as many changes as possible to the Checkboxes, which will change the CheckState property of the nodes. When the user is done, he/she can press the save button, and all these changes will be written to the database.
I also have an update command in the SqlDataAdapter, which is fetching the data.
So, currently I am looping in a for loop to populate the tree nodes. This process succeeds. But now for users to check/uncheck these check boxes and for me to update the CheckState of these tree nodes, I need to be able to capture these state changes in the data table from where I read the data, and commit these changes to the database.
I am not sure how to bind the data I read from the database to the TreeNode(s) so that I can make the above two things happen.
Help appreciated.
|
|
|
|
|
It looks like your options a) and b) are fighting with each other, but that could just be a misunderstanding on my part. (Committing immediatly would make a save button rather useless.) I'll assume that you want to remember the changes and only send them to the database when they hit "save".
The "Tag" memeber of the TreeNode is where you want to store the data to link the node with the data row. You can do this in a lot of ways. One way would be to simply stick the data row into that tag. If that isn't enough, you can create a class of your own that holds all the data you need. Then, put that class into the Tag of the TreeNode.
One of these methods should get you to where you are going. Good luck!
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
John,
Thanks for your reply.
Just need some more clarification on your suggestion.
I am aware of the "Tag" property of the TreeNode. Once I am done processing the For loop, the tree is populated successfully. At this moment there is no connection between the data table (which was used to populate the tree) and the TreeNodes. I can capture user's action when he/she checks/unchecks a node in the AfterCheck event. But then at that moment, since there is no binding between the data table and the TreeNode data, changes will not be recorded in the data table.
Are you suggesting that I store the node's CheckState value in the node tag, and then some how link the data table and the data in the tag property of all the nodes and then update the source data table manually? It can be done but just wondering if there is a better way so once the nodes and the data table are bound, CheckState changes in these nodes and the data table will happen automatically and the two will be synchronized all the times. If I implement this manually in a round about way I am afraid I will miss some critical steps and mess up something.
Just like DataGrid can be bound to a data table. Is there a similar thing such as binding TreeView control to a data table. MSDN has an example "Extending the TreeView Control" which uses data source but does not go along the path I am trying to go.
Also, the two options I am implementing are mutually exclusive.
John, again, thanks for your help.
|
|
|
|
|
You should set the Tag property while you are creating the nodes, not in a process after the nodes are created. The tag property should have, at minimum, some way for you to find the database row that needs to be updated.
One simple way of doing this is to:
* Retrieve your data.
* Construct the tree nodes, setting the Tag to that row's ID.
* When the user clicks a node, call the database, setting the appropriate value for the row which is identified by the Tag.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
I am using a three state check box. When a user clicks on a node, I recursively set the CheckState property of the children nodes and parent nodes appropriately. My second option (pressing the save button and committing changes to the DB once) is more suited here as that will take only one round trip call to the database.
John, could you demonstrate by some example how one would update the local data table and the CheckState value in the nodes?
In order in order to successfully record all the changes in the nodes to the data table, I'll loop through all the nodes and copy the CheckState value to the data table. Basically, I have to traverse the entire tree, starting with the root. Is that how you are envisioning?
BTW, I am setting the tag property as I am constructing the nodes, as you suggested.
Help appreciated.
Thanks again
|
|
|
|
|
The save button sounds workable.
That's good that you're already storing the information about which database row corresponds to the TreeNode. Without it, you would have a very hard time doing this.
An example? That's a very tall order, since I don't know anything about the code you are using (data access, type of database, etc.). So, some pseudo-C# code is probably the best I can do.
<br />
private void SaveButton_Clicked(object sender, EventArgs e)<br />
{<br />
SomethingOrOther data = new SomethingOrOther();<br />
<br />
foreach (TreeNode node in yourTree.Nodes)<br />
{<br />
YourClassInfo info = node as YourClassInfo;<br />
data.QueueUpdate(info.Row, node.Checked);<br />
}<br />
<br />
data.Save();<br />
}<br />
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
I basically just want to send a 2 part message. Part 1: text, Part 2: Html.
Any ideas on how I'm going to get this into my .NET application?
|
|
|
|
|
http://www.quiksoftcorp.com/freesmtp/
in case anyone wants to know
|
|
|
|
|
Hi All,
I have created a database in SQL and setup relationships the works. What happens is, when you enter info from a website, numeric values gets written to SQL.
What I need is to display the data behind the values in a datagrid. I have created a stored procedure to inner join the needed data but how do I execute the stored procedure to display the data in a datagrid?
Thanks!
Illegal Operation
WannaBe and GonnaBe Systems Developer
|
|
|
|
|
You will want to look at the System.Data and System.Data.SqlClient namespaces.
One way to do what you're attempting would be to create a System.Data.SqlClient.SqlConnection object using a valid connection string for your database, then create a System.Data.SqlClient.SqlCommand using the connection with the name of your stored procedure as the CommandText , and StoredProcedure as the CommandType . Finally, create a System.Data.SqlClient.SqlDataAdapter object based on the SqlCommand object (there is a constructor that accepts a SqlCommand instance).
Once the DataAdapter was created, you could declare a System.Data.DataTable and call the SqlDataAdapter's Fill method to retrieve your data into the DataTable . After the data is retrieved and stored in memory in your DataTable , you can set your DataGrid 's DataSource property to be the DataTable (or you can further use a System.Data.DataView of the DataTable if you want to sort your results), and call the DataGrid 's DataBind method. The DataGrid should then display your results.
There's quite a lot more that can be done with configuring the DataGrid , but these are the basics. There are also several different ways you could get the data you're after using a variety of combinations of types in the System.Data namespace and its sub-namespaces, but this is fairly straightforward.
Hope this helps.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Hi there
In the MSDN i read that the Timeout property from the WebRequest class isn't available when using the asynchronus way. When i try to webrequest a uri which doesnt exists, the program hangs a couple of seconds before throwing an exception. If the main part of the uri exists but e.g. the path is incorrect, then ill get an error response right after.
How to reduce the hang/timeout when webrequesting an uri which doesn't exist? Any ideas?
--------------------
Thanks for reading
|
|
|
|
|
i just created a NT service project with the help of Service Project Template given in VS,and installed it by using installutil servicename.exe
however its not appearing in Service Panels,here are contents i see on console window
Beginning the Install phase of the installation.
See the contents of the log file for the c:\windowsservice1\windowsservice1\bin\
debug\windowsservice1.exe assembly's progress.
The file is located at c:\windowsservice1\windowsservice1\bin\debug\windowsservi
ce1.InstallLog.
Installing assembly 'c:\windowsservice1\windowsservice1\bin\debug\windowsservice
1.exe'.
Affected parameters are:
assemblypath = c:\windowsservice1\windowsservice1\bin\debug\windowsservice1.e
xe
logfile = c:\windowsservice1\windowsservice1\bin\debug\windowsservice1.Instal
lLog
No public installers with the RunInstallerAttribute.Yes attribute could be found
in the c:\windowsservice1\windowsservice1\bin\debug\windowsservice1.exe assembl
y.
The Install phase completed successfully, and the Commit phase is beginning.
See the contents of the log file for the c:\windowsservice1\windowsservice1\bin\
debug\windowsservice1.exe assembly's progress.
The file is located at c:\windowsservice1\windowsservice1\bin\debug\windowsservi
ce1.InstallLog.
Committing assembly 'c:\windowsservice1\windowsservice1\bin\debug\windowsservice
1.exe'.
Affected parameters are:
assemblypath = c:\windowsservice1\windowsservice1\bin\debug\windowsservice1.e
xe
logfile = c:\windowsservice1\windowsservice1\bin\debug\windowsservice1.Instal
lLog
No public installers with the RunInstallerAttribute.Yes attribute could be found
in the c:\windowsservice1\windowsservice1\bin\debug\windowsservice1.exe assembl
y.
Remove InstallState file because there are no installers.
The Commit phase completed successfully.
any help?because i dont think there is some mistake in code or calling methods
Thanks
MyBlogs
http://weblogs.com.pk/kadnan
|
|
|
|
|
Hi,
The key portion of the error message is this:
<br />
No public installers with the RunInstallerAttribute.Yes attribute could be found in the c:\windowsservice1\windowsservice1\bin\debug\windowsservice1.exe assembly.
This means that you don't have a ServiceInstaller with the [RunInstaller] attribute set to yes. Check your code to see if that is missing completely, or if it's just needs a little tweak. (And look up ServiceInstaller in the docs if you haven't already.)
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
I have dataset which is binded to datagrid and dateformating is done based on culture. This happens fine with out any problem.
If my dataset is retrieved as a xml string using dataset.GetXML then converted to dataset and binded to datagrid. The date formatting wont take place instead it displays in the following format
2005-02-09T14:13:24.8280000-00:00.
But I want the dateformatting to take place on datagrid in either of the case.
Padvit
|
|
|
|
|
Hi, i want to open a word document in an existing class including the below code.
.........
.........
object fileName = strFileName;
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
oDoc = oWordApplic.Documents.Open(ref fileName, ref missing,ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible,ref missing,ref missing,ref missing, ref missing);
oDoc.Activate();
It works fine in my computer which includes Office 2003, but if I try to run this code in another computer which includes Office 2002 it gives the following error:
Error-->"System.Exception: object reference not set to an instance of an object.
this error occurs in the line of oDoc = oWordApplic.Documents.Open(..) .
Can anybody help me please.
Fatih Sen
|
|
|
|
|
Hi!
The type libraries for different Word versions are not compatible.
You should program against the lowest version number, i.e. get yourself a primary interop assembly of Word97 and use only the objects defined there.
That way your program should work with Word97 and up.
If you really need objects/functionality from later Word versions, then you will have to pick the prim. interop assembly for this version, but your program will not work with a lower Word version.
Regards,
mav
|
|
|
|
|
I used Microsoft Office 11.0 Object Library. So, should I use lower version like Mic. Off. 10.0 Library. Do you mean that?
Fatih Sen
|
|
|
|
|
|
Hi again mav.
I changed the Microsoft.Office 11.0 Object Library with Microsoft.Office 10.0 Object Library. And now it gives the following error:
System.Exception:System.Runtime.InteropServices.COMException. There is insufficient memory.Save the document now at Microsoft.Office.Interop.Word.Documents.Open(....)
Do you know why this situation occurs now?
Fatih Sen
|
|
|
|
|
Now it works. After changing from Microsoft.Office 11.0 Object Library with Microsoft.Office 10.0 Object Library I got the above error. Then,start>run>dcomcng. Clicking the Microsoft Word Document , in the Identity I changed the user to "interactive user".
Thanks mav.
Fatih Sen
|
|
|
|
|
I have a report ex:
ReportDocument report=new ReportDocument();
report.Load("path to the report);
DataSet dataSet=new DataSet();
I have a connection to a database SqlConnection...,
SqlDataAdapter adapter=new SqlDataAdapter("Select * From database Where x='y'",connection);
adapter.Fill(dataSet);
report.SetDataSource(dataSet);
crystalReportViewer.ReportSource=report;
and when I run the report not returns the date what I said in sql,he return all the rows from table.
Please help me.
|
|
|
|
|
Did you save your data with "Save Data With Report"?
Is the query valid? Check what the query returns. Hope this will help.
<italic>Work hard, Work effectively.
|
|
|
|
|