|
ajay 2010 wrote: i tried it n got the solution.
I am sorry but this is not a solution; your code does not solve the problem you set out in your orignal post. The first five lines of code serve no purpose except to ensure that whatever number you input between 4000 and 7998 will give the answer valid. So if you input 5555 it will say valid, even though 5555 does not contain a 2. As I said before, go back to your study guides and spend some more time learning about strings and character recognition, among other things.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
ya what u told is true...
whether the logic i used in this program is correct or entirely i have to change....
|
|
|
|
|
Hi All,
Can we call a wcf service manually by using SOAP envelope, without adding a web reference?Jack Sparrow
--------------------------------------
Defeat is not the worst of failures. Not to have tried is the true failure.
|
|
|
|
|
No, why would you want to I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I don't know if you know the GEDCOM file format (.ged, genealogy file standard[^]), but I'm trying to read one and I want to put it in a listview. The following code opens a gedcom file, and saves the data (per person) to a treeview.
StreamReader reader = new StreamReader(@"test.ged");
string[] lines;
string file_content = reader.ReadToEnd();
lines = file_content.Split(Environment.NewLine.ToCharArray()[0]);
this.Text = lines.Length.ToString();
TreeNode currentperson = new TreeNode();
foreach(string line in lines)
{
string newline = line.Replace("\n", "");
newline = newline.Replace("\r", "");
try
{
if (newline[0].ToString() == "0")
{
newline = newline.Replace("@", "");
newline = newline.Replace("0", "");
newline = newline.Replace("INDI", "");
TreeNode newperson = new TreeNode(newline);
gedcomtree.Nodes.Add(newperson);
currentperson = newperson;
}
else
{
TreeNode currentnode = new TreeNode(newline);
currentperson.Nodes.Add(currentnode);
}
}
catch { }
}
Now my question is: How can i sort the elements in a persons' node aswell?
Example:
1 BIRT
2 DATE 01 FEB 1750
2 PLAC EDINBURGH
3 NOTE Old place.
1 DEAT
2 DATE 02 FEB 1800
etc.
Should make:
- BIRT
-- DATE 01 FEB 1750
-- PLAC EDINGBURGH
--- NOTE Old place.
- DEAT
-- DATE 02 FEB 1800
(In a treeview)
Could someone help me out on this one? Im trying to get this to work for 3 days now, and i'm still stuck
Thanks in advance,
ZaegraMotivation is the key to software development.
|
|
|
|
|
Zaegra wrote: string newline = line.Replace("\n", ""); newline = newline.Replace("\r", ""); try
{ if (newline[0].ToString() == "0") { //MessageBox.Show("newperson wotwot!"); newline = newline.Replace("@", ""); newline = newline.Replace("0", ""); newline = newline.Replace("INDI", ""); TreeNode newperson = new TreeNode(newline); gedcomtree.Nodes.Add(newperson); currentperson = newperson;
One easy way will be to move all the newline.Replace(); in a separte loop, sort the array of strings, and then add the Nodes from the sorted array.
|
|
|
|
|
When I pass an argument to a BackgroundWorker using RunWorkerAsync I can access that argument via the Argument property of DoWorkEventArgs in DoWork - is it possible to access that argument in the RunWorkerCompleted method?
|
|
|
|
|
Hi,
the Argument parameter is not passed automatically to the completion handler, however the latter gets two things: UserState and Result. AFAIK the UserState can be set as an optional parameter to ReportProgress(), whereas the Result is a member of DoworkEventArgs.
So it seems you have two ways to pass Argument to the completion handler, both requiring a little bit of code.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
UserState isn't passed to the completion handler - Result is but it seems a dreadfully clunky way to pass the argument. Still, if that's all there is I suppose I can just set the result as soon as DoWork starts so that there's a good chance it will make it through to the Completed handler.
|
|
|
|
|
Hmm, that doesn't work as Result is invalid if an exception was thrown during DoWork.
I think I will just store the object in a class variable and access that in both the DoWork and Completed events. I have seen conflicting versions at to how valid that is but it seems to work.
|
|
|
|
|
Interesting.
I do agree the Argument parameter should have been made available to all BGW event handlers.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
I agree too so I've coded up a quick CustomBackgroundWorker Tip/Trick here[^].
|
|
|
|
|
I trust you included proper attributions. Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
I'll edit it and link to this thread!
[Edit] Done [/Edit]
|
|
|
|
|
You could rewrite the entire component and code it as you wish. There is publicly available source code available here[^] that can be easily adapted.
The easiest way however would be to subclass the existing component and add a readonly property as below:
using System;
using System.ComponentModel;
using System.Windows.Forms;
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
Load += new EventHandler(Form1_Load);
}
void Form1_Load(object sender, EventArgs e)
{
CustomBackgroundWorker bgw = new CustomBackgroundWorker();
bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
bgw.RunWorkerAsync("Test");
}
private void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
CustomBackgroundWorker bgw = sender as CustomBackgroundWorker;
if (bgw != null && bgw.Argument != null)
{
MessageBox.Show((string)bgw.Argument);
}
}
}
public class CustomBackgroundWorker : BackgroundWorker
{
private object argument;
public new void RunWorkerAsync(object argument)
{
this.argument = argument;
base.RunWorkerAsync(argument);
}
public object Argument
{
get { return argument; }
}
}
|
|
|
|
|
Looking into the implementation in a little more detail, the reason you can't access Result if an exception is thrown is RunWorkerCompletedEventArgs derives from AsyncCompletedEventArgs . The RunWorkerCompletedEventArgs inplementation of Result is:
public object Result {
get
{
base.RaiseExceptionIfNecessary();
return result;
}
} and the AsyncCompletedEventArgs.RaiseExceptionIfNecessary is:
protected void RaiseExceptionIfNecessary()
{
if (Error != null)
{
throw new TargetInvocationException(SR.GetString(SR.Async_ExceptionOccurred), Error);
}
else if (Cancelled)
{
throw new InvalidOperationException(SR.GetString(SR.Async_OperationCancelled));
}
} This doesn't solve your issue - but now you can see why it exists, and what you would need to change if you wanted to implement your own BackgroundWorker where Result is always available.
|
|
|
|
|
On reflection, I agree with Luc in his comment above that Argument should be available in all the event handlers and not really a property of the BackgroundWorker as it was in my simple first suggestion.
I figured I could make use of this myself so I've coded a new CustomBackgroundWorker and needed event args classes. I figured I'd share it as a Tip/Trick here[^].
|
|
|
|
|
I have more comments on BGW, e.g. why do we need to set WorkerReportsProgress and WorkerSupportsCancellation true to start using those features?
And why do its events not offer a sender object, as Controls do? so several BGW could easily share an event handler.
And why do BGWs not have a Tag property? maybe everything should have one, maybe not very OOish, but often very useful?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Luc Pattyn wrote: why do we need to set WorkerReportsProgress and WorkerSupportsCancellation true
Once again I agree, I made a GenericBackgroundWorker[^] some time ago and that is one of the things I addressed there by setting the fields to true in the constructor. Check out this section[^].
Luc Pattyn wrote: And why do its events not offer a sender object
They do - I've just checked!
Luc Pattyn wrote: why do BGWs not have a Tag property
Easily added, although it would need to have locks applied as it's almost guaranteed to be accessed from another thread.
|
|
|
|
|
DaveyM69 wrote: They do
My mistake. So the "argument" problem could have been handled with a dictionary technique (and all its pitfalls).
DaveyM69 wrote: (Tag property...) would need to have locks applied
That depends on how it gets used, as usual. Locking should be considered, and when necessary, implemented at the highest possible level.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
I am wondering if it is possbile to show multiple line for this param name "searchPattern" in the ///summary section. (Documentation explaining about the method and its parameters.
I mean to show as this in 2 lines.
For all files, use "*.*".
For hex files only, use "*.hex"
Instead of on one line.
For all files, use "*.*". For hex files only, use "*.hex"
<code snippet below>
/// <summary>
/// Gets the list of filenames in a certain directory path.
/// </summary>
/// <param name="path">Directory path</param>
/// <param name="searchPattern">For all files, use "*.*". For hex files only, use "*.hex"</param>
/// <returns> List of filenames in a directory path.
/// </returns>
public string[] GetFilenamesInDirectory(string path, string searchPattern)
{
....
}
|
|
|
|
|
Try:
/// <param name="searchPattern">For all files, use "*.*".<br/>For hex files only, use "*.hex"</param>
Modified: just realised you might have meant like this:
/// <param name="searchPattern">
/// For all files, use "*.*".
/// For hex files only, use "*.hex"
///</param>
|
|
|
|
|
Try this:
There are a set of pre-defined tags that one can use why doing XML style comments. Place a " < " and VS will display them to you."No matter how many fish in the sea; it will be so empty without me." - From song "Without me" by Eminem
|
|
|
|
|
This is what I did and it did work!
/// <param name="searchPattern">For all files, use "*.*".<para/> For hex files only, use "*.hex"</param>
Thanks for the help!
|
|
|
|
|
Hi,
I cant figure out how to switch my customcontrols when clicking on a menubar-button.
I have a MainWindow containing the following XAML:
<DockPanel x:Name="MainWindow">
<Menu Name="dropDownMenu"
DockPanel.Dock="Top">
<MenuItem Name="dropDownPage1" Header="File">
<MenuItem Header="Page1" Click="dropDown_Page1"/>
</MenuItem>
<MenuItem Name="dropDownPage2" Header="File">
<MenuItem Header="Page2" Click="dropDown_Page2"/>
</MenuItem>
</Menu>
<Grid Name="gridMainContent" DockPanel.Dock="Top">
<TextBlock>placeholder main content</TextBlock>
</Grid>
<Grid Name="gridStatusBar" DockPanel.Dock="Bottom">
<TextBlock>placeholder statusbar</TextBlock>
</Grid>
</DockPanel>
The task is when clicking on one menubutton i.e. "dropDown_Page1", changing the content of the grid "gridMainContent".
Is there a way to place customcontrols into a grid without code in any *.cs File ? It would be wonderfull if somebody could help me on this.
Cause I´m new to WPF, I welcome you to show me other ways of doing this!
Thx! PingOfDeath
|
|
|
|