|
@Keld, thanks for the info...
I remain joe!
|
|
|
|
|
I'd use an XmlDocument.
string s = "<api_result><data><credits>33</credits></data><call_result><result>True</result><error /></call_result></api_result>" ;
System.Xml.XmlDocument doc = new System.Xml.XmlDocument() ;
doc.LoadXml ( s ) ;
System.Xml.XmlNode nod = doc.DocumentElement.SelectSingleNode ( "data/credits" ) ;
string v = nod.InnerText ;
|
|
|
|
|
|
Boipelo wrote: I want to know the best way of doing this...
Depends on what "best" means.
But since you are doing nothing but a simple value lookup what you are doing is probably the most performant (although probably not in a significant way.)
There are upside/downsides to ignoring the XML itself. For example if they change element names on the message your code still works. But if they add another element first with a numeric value it doesn't.
Conversely using XML if they change names then the code would fail. But if they add another element it would still work.
|
|
|
|
|
I was also scared of "...if they add another element with a numeric value". I am not seeing them changing the "element name", that wont happen.
Thanks for the comment.
I remain joe!
|
|
|
|
|
Boipelo wrote: I was also scared of "...if they add another element with a numeric value"
but only if it is first.
You can do a indexOf for the element name and then start parsing the numeric.
|
|
|
|
|
I'm trying to add an event handler for form closing event. I'm not very good at doing event handlers. I looked at http://stackoverflow.com/questions/7076751/how-do-i-avoid-validating-cancel-causing-app-exit-to-hang[^], among other places on the internet, but the thread is not getting to my method. It wasn't building until I added the property for FormClosing at the top. Hopefully someone here has an idea why it's not working. Thanks!
public partial class GenericPC : UserControl
{
...
public FormClosingEventHandler Closing { get; set; }
public Control GetPC(<params>)
{
...
this.Closing += new System.Windows.Forms.FormClosingEventHandler(this.updateLogsOnClose);
...
}
private void updateLogsOnClose(object sender, System.ComponentModel.CancelEventArgs e)
{
logCountsToFile(logCountFile);
}
...
}
modified 21-Mar-13 11:28am.
|
|
|
|
|
The event name is Closing .
|
|
|
|
|
I changed it from FormClosing to Closing, as I changed in my code shown above, and it's still not going to my method when the form closes. Any ideas? It doesn't seem the like property for Closing gets called by anything. Do I need to set it somehow? Closing was causing a build error before I defined it. Maybe there's a system method I need to enable somewhere to get it defined by visual studio?
|
|
|
|
|
MichCl wrote: property for Closing
Get rid of that.
|
|
|
|
|
public Control GetPC(<params>)
{
...
this.Closing += new System.Windows.Forms.FormClosingEventHandler(this.updateLogsOnClose);
...
} That's not the form, and your usercontrol will not raise a FromClosingEvent; you'd need a reference to the form if you want to hook it's "Closing" handler (in the same way you need an instance when you use one of it's properties).
Alternatively, you could use the "Parent" property of your usercontrol to find the owning form.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks Eddy. I'm trying to figure out how to use theParent's Form to set me up with the Closing Handler. For some reason, the below code is not building. It says "System.Windows.Forms.FormClosingEventHandler is a type which is not valid in the given context". Any idea?
public partial class GenericPC : UserControl
{
...
public FormClosingEventHandler Closing { get; set; }
public Control GetPC(<params>, Form theParent)
{
...
theParent.Closing += new System.Windows.Forms.FormClosingEventHandler(this.updateLogsOnClose);
...
}
private void updateLogsOnClose(object sender, System.ComponentModel.CancelEventArgs e)
{
logCountsToFile(logCountFile);
}
...
}
|
|
|
|
|
Your modification is correct; but it looks like the eventhandler could use a different signature;
private void updateLogsOnClose(Object sender, FormClosingEventArgs e) As an alternative solution;
1 using System;
2 using System.Windows.Forms;
3 using System.Collections.Generic;
4
5 namespace test
6 {
7 class MyControl: UserControl
8 {
9 protected override void OnHandleCreated(EventArgs e)
10 {
11 base.OnHandleCreated(e);
12 FindForm().FormClosing += new FormClosingEventHandler(MyControl_FormClosing);
13 }
14 void MyControl_FormClosing(object sender, FormClosingEventArgs e)
15 {
16 System.Diagnostics.Debugger.Break();
17 }
18 }
19 class Program
20 {
21 public static void Main(string[] args)
22 {
23 using (var f = new Form())
24 {
25 MyControl uc = new MyControl() { Dock = DockStyle.Fill };
26 f.Controls.Add(uc);
27 f.ShowDialog();
28 }
29 }
30 }
31 }
The reason I'm not calling the FindForm method in the constructor of the UserControl is because it will not be assigned to a form at that point. (It's created on line 25, and added to the form on the next line)
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
If you definitely need access to the closing event from your control, you need to walk up the Parent hierarchy until you find the Form. It would look something like this:
private Form ParentForm(object item)
{
if (((Form)item).Parent is Form)
return ((Form)item).Parent;
return ParentForm(item);
} Then, it's a simple matter of hooking into the closing event handler.
I really wouldn't recommend doing it this way, but you could.
|
|
|
|
|
I got it working!! Thanks for your help!! It turns out I was missing "new":
theParent.FormClosing += new FormClosingEventHandler(this.updateLogsOnClose);
|
|
|
|
|
Hi,
I want to combine two drawings into one,and place in a line as show below
How to Upload pictures!!!
|
|
|
|
|
You need to provide a lot more detail about this problem: what sort of drawings, place on a line where ... ?
Use the best guess
|
|
|
|
|
Could you teach me how to upload pictures? I have no idea
|
|
|
|
|
What sort of pictures, and where do you want to upload them from and to? You really need to think about what problem you are trying to solve, and provide some more useful details.
Use the best guess
|
|
|
|
|
You are not allowed to upload pictures here. You should upload them to a free image hosting site and provide a link in your question. You also need to be a bit clearer in your question, as I don't think anyone understands what you are trying to get at. If your English is not so good, try use Google translate.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
What format are the drawings in and how do you want to combine them?
|
|
|
|
|
The drawings are designed by AutoCAD(*dwg/*dxf). For each drawing document, there is only one drawing of A4 size. Now, I want to gather 2 drawing-files into a drawing file, so that ,I can preview the 2 drawings in a file at the same time.
|
|
|
|
|
Seems simple enough, and I have looked hard and found many code sources (because some here might say this has been asked and answered), but none of them seem to work (I am showing some below...there are more).
Teh primary error seems to be the following error (unable to cast object of type 'system.data.datarowview' to type 'system.string ) or something similar to this. It seems like I solved this problem a while ago by giving up on the check list box and using a list view box with the show checkbox property added, but I cannot find my original code. So, in a nutshell....I want to simply return the string values for the checked items in the control and add them to an array or arraylist (either will do). BTW...the checklistbox control was filled using an SQL query (shown also), in case that makes a difference. You guys have almost always come up with a solution of sorts, and I thank you again in advance for your great assistance and talent...Regards, Pat
//Query Code
ArrayList al = new ArrayList();
Conn.Open();
SqlDataReader dr = Comm.ExecuteReader();
if (dr != null)
while (dr.Read())
{
al.Add(dr[0]);
}
Conn.Close();
foreach(string s in al)
{
checkedListBoxServices.Items.Add(s);
}
|
|
|
|
|
using System;
using System.Windows.Forms;
using System.Collections.Generic;
namespace test
{
class Program
{
public static void Main(string[] args)
{
using (var f = new Form())
{
var tb = new TextBox()
{
Multiline = true,
Dock = DockStyle.Top,
Height = 50
};
var clb = new CheckedListBox() { Dock = DockStyle.Fill };
clb.Items.AddRange(new string[] { "One", "Two", "A half" });
clb.SetItemChecked(0, true);
clb.SetItemChecked(2, true);
f.Controls.AddRange(new Control[] { clb, tb });
foreach (var element in clb.CheckedItems)
{
tb.Text += ((string)element) + Environment.NewLine;
}
f.ShowDialog();
}
}
}
} "CheckedItems" will return the objects that are checked. If you throw strings in there, then it's strings that it returns. Otherwise, it'll return the object, and you'd prolly need to call the "ToString" method on that object or build a string of it's properties.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
YES YES YES YES YES YES YES YES ...........
Thank You Eddy...VERY Much...I'd be too embarrassed to tell you how much time I spent of this yesterday. The following is the actual code that I extracted from your sample to resolve this:
foreach (var element in checkedListBoxServices.CheckedItems)
{
textBox1.Text += ((string)element) + Environment.NewLine;
}
It seems that your use of the new context (var) replacing my use of string and then casting for the result later with (string) makes a big difference ... I need to look at this again to really understand it, but I know that I can thanks to you. Much appreciation and thanks...Best Regards, Pat
ps: after searching for this yesterday, and finding 'solutions' that were a page long and STILL did not work, I am sure that hundreds of others will be wanting the thank you as well for a concise usable solution... Pat
|
|
|
|