|
Like with all "new" (I mean "new" as in "new to you") API/libraries, it is just a matter of figuring out the style or pattern to the thing (what their methodology for placing what classes where). Once you realize that it is easy to search for things you aren't exactly sure where they exist. I would recommend getting familiar with the namespace layout. Once you realize that all UI elements are under System.Windows.Forms you could easily find the OpenFileDialog class. Lo and behold, SaveFileDialog is there as well! Once you realize the IO is in System.IO you can find all sorts of ways to stream data.
Picking up a new API/library is like learning to ride a bike all over again. It is a little painful but the real way to do it is jump on and go. It might have taken you a bit to find OpenFileDialog but it will get faster the more familiar you get with the object layout.
|
|
|
|
|
I have an HTML file i want to read certain parts of based on the tags round them BUT i dont want to read the tags in to the string im reading the text into after i have located it.
So here is what i have been doing so far:
1) Read in the HTML file to a string.
2) Read through the string char by char placing returns where tags are. So that each tag is shunted onto its own line and so is each peice of untagged text.
3) Read line by line checking the tags.If its the tag i want read the entire line bellow then stop reading and start checking again.
This was easy to code as it was just a matter or adding returns when it read a "<"or ">"
Then reading line by line, ignoring any lines that where not direclty below the tags i wanted..
But I feel like I'm double handling the data, would my program be more efficient if it looked for the lines I wanted while it was scanning for tags during stage 2 where it was previously just adding returns.
SO it would:
1) Read through line by line.
2) See a tag
3) Check the tag
4) If OK read the text to the next "<"
Or are both ways close enough in efficienty to not warrent a rewrite of the code?
|
|
|
|
|
Since HTML is simply a piece of XML code, just use a Xmlreader. There are lots of articles/discussions about that, here in Code Project.
___________________________________
Tozzi is right: Gaia is getting rid of us.
My Blog [ITA]
|
|
|
|
|
Actually, that is far from the truth. XHTML is XML using a default namespace defined by a schema similar to HTML, but HTML is not XML for one big reason: HTML is not well-formed. The <br> tag, for example, does not define a closing tag and is not self-closed. You can, but most generators and even web developers don't do this.
HTML is defined by SGML as is XML but HTML is far more lax. In order to parse HTML and tokenize it by its tags like you could an XML document, you have to use a more lax parser. GotDotNet has one available at http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=B90FDDCE-E60D-43F8-A5C4-C3BD760564BC[^] that can parse HTML for you and tokenize it as such.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Your first way will take about twice as long. Wether that's enough of a performance hit to justify a refactoring depends on how large your html files are, and how often you need to parse them.
|
|
|
|
|
I have intalled .Net Framework 1.1 With SP1 on my test PC which is Running on Windows XP Home Edition and Windows 2000 Professional. My app crashes with some unknown Exception. I have tried a simple Windows App with just a few default controls it still doesnt work.
Error Shows
Common Language Runtime Debugging Services
Application Has Generated an exception that could not be handled
ProcessID = 0x128(288) ThreadID= 0x546(???)
What could be wrong with it
I have tried Both debug and release versions
Zishan Haider
|
|
|
|
|
How can I programaticly clear selections in lvA when the user selects something from lvB and vice versa. At the moment I'm using the SelectedIndexChanged event and looping through the other lvs items setting selected to false. The problem is that while clicking on an item in lvB will trigger the clearingof lvAs selections, doing so triggers lvA's SelectedIndexChanged event which clears the just made selection in lvB.
|
|
|
|
|
I've added bool flags set by the Enter and Leave events on each LV. It works properly but feels like a hack. Is there a more graceful solution?
|
|
|
|
|
The controls are separate controls without any sort of policy allow for a single selection among different instances of the same control (like a radio button). What you've done isn't really a hack but a necessity, but there are alternatives you could consider.
Perhaps write a class that really is just a collection of your ListViewItemCollection instances for each ListView . You could implement an event handler on that class that listens for ListView.SelectedIndexChanged and uses state to ignore the next raised event since you'll be selecting a new item. That hanler (or some other callee) would then clear the selection for the other ListViewItemCollection instances.
Below is a really quick sample I threw together of such a manager:
using System;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
class Test : Form
{
static void Main(string[] args)
{
bool mutuallyExclusive = false;
try
{
if (args.Length > 0)
{
mutuallyExclusive = bool.Parse(args[0]);
}
}
catch
{
Console.Error.WriteLine("Invalid argument; expecting \"true\" or \"false\".");
Environment.Exit(87);
}
Application.Run(new Test(mutuallyExclusive));
}
Test(bool mutuallyExclusive)
{
ListView[] views = new ListView[] {
new ListView(),
new ListView()
};
foreach (ListView view in views)
{
view.HideSelection = false;
for (int i = 0; i < 5; i++)
{
ListViewItem item = new ListViewItem("Item " + i);
view.Items.Add(item);
}
}
Controls.AddRange(views);
views[0].Name = "view1";
views[0].Location = new Point(8, 8);
views[0].Size = new Size(200, 100);
views[1].Name = "view2";
views[1].Location = new Point(views[0].Width + 8, 8);
views[1].Size = views[0].Size;
Width = 24 + views[0].Width + views[1].Width;
Height = 24 + views[0].Height + views[1].Height;
new ListViewSelectionManager(mutuallyExclusive).AddRange(views);
Text = "Mutually Exclusive ListView Selection Example";
}
}
public class ListViewSelectionManager
{
bool mutuallyExclusive = false;
ArrayList views = new ArrayList();
bool clearing = false;
public ListViewSelectionManager(bool mutuallyExclusive)
{
this.mutuallyExclusive = mutuallyExclusive;
}
ListViewSelectionManager() {}
public void AddRange(ListView[] views)
{
foreach (ListView view in views)
{
view.SelectedIndexChanged += new EventHandler(OnSelectedIndexChanged);
this.views.Add(view);
}
}
void OnSelectedIndexChanged(object sender, EventArgs e)
{
if (sender == null) throw new ArgumentNullException("sender");
Control c = sender as Control;
Console.WriteLine("SelectedIndexChanged event raised from " + c.Name);
OnListViewSelectionChanged(sender, e);
if (mutuallyExclusive && !clearing)
{
clearing = true;
foreach (ListView view in views)
{
if (sender != view)
{
Console.WriteLine("Clearing selection for " + view.Name);
view.SelectedItems.Clear();
}
}
clearing = false;
}
}
public event EventHandler ListViewSelectionChanged;
protected virtual void OnListViewSelectionChanged(object lv, EventArgs e)
{
if (ListViewSelectionChanged != null)
{
ListViewSelectionChanged(lv, e);
}
}
public ICollection SelectedItems
{
get
{
ArrayList list = new ArrayList();
foreach (ListView view in views)
{
list.AddRange(view.SelectedItems);
}
return list;
}
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath Stewart wrote:
The controls are separate controls without any sort of policy allow for a single selection among different instances of the same control (like a radio button). What you've done isn't really a hack but a necessity, but there are alternatives you could consider.
I'd suspected as much, but was hoping there might be a way to differentiate between a user change of selection and a programatic one, since I only wanted clearing on the former.
With only 2 lvs on the form, the containerclass idea is serious overkill for my current needs/
|
|
|
|
|
The only way to detect programmatic vs. user-click is to get the current mouse position, translate that to client coordinates from screen coordinates, and detect if the mouse is over a particular ListViewItem . It actually gets pretty messy.
dan neely wrote:
With only 2 lvs on the form, the containerclass idea is serious overkill for my current needs/
As you know if programming, change is the only constant ( or those things declared with const ) The manager idea is actually pretty simple and very flexible and is scalable for future needs. It also keeps from writing spaghetti code. The goal of object-oriented programming is to encapsulate concepts and code into re-usable classes, and the manager approach is one such way of doing that. Rather than writing similar (if not the same) code for a specific sequence every time you need it you can reuse this class and encapsulate all the selection code inside it. It's just an abstract approach to solving the problem and just one idea for handling it.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath Stewart wrote:
The only way to detect programmatic vs. user-click is to get the current mouse position, translate that to client coordinates from screen coordinates, and detect if the mouse is over a particular ListViewItem. It actually gets pretty messy.
I'm trapping doubleclicks in two columns on one lv so I've got a fair idea of what's involved in that route, I don't think it's that ugly though. An addition to the framework allowing for a direct check of what cell was clicked on would be a nice improvement though.
|
|
|
|
|
That would be a useful feature. To make such suggestions or reports possible bugs please use the MSDN Product Feedback Center[^]. That ties in with our internal defect tracking system so I promise we're listening! Please keep in mind, however, that .NET 2.0 features are already locked down.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath Stewart wrote:
That would be a useful feature. To make such suggestions or reports possible bugs please use the MSDN Product Feedback Center[^]. That ties in with our internal defect tracking system so I promise we're listening! Please keep in mind, however, that .NET 2.0 features are already locked down.
Is there any way to specify v1.1 as the version? I only see v2.0 betas available in the combo box?
|
|
|
|
|
It would be a design change request for a future version. Just specify one of the v2.0 betas or any future versions and it will get moved as needed. You can request that it be added to v1.1 but we typically don't add features to a previous version.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
How to save change from sql db table (as we take Differential Backup of db) in script form. And run script through C#.Net coding.
|Muhamad Waqas Butt|
waqasb4all@yahoo.com
www.sktech.freewebspace.com
|
|
|
|
|
I am a student busy developing an application in C# donet, I am busy working with crystal reports. I need my reports to be dynamic, I want to pass a different SQL statement every time (eg a report that will generate information of the selected customer)
string SQL = "SELECT ClientID, Name FROM Client WHERE ClientID = 14544";
DataSet ds = new DataSet();
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=TKOAcademic;Integrated Security=SSPI;Connect Timeout=30");
System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
oleDbDataAdapter1.SelectCommand = new System.Data.OleDb.OleDbCommand(SQL, conn);
CrystalReport1 cutsReport = new CrystalReport1();
oleDbDataAdapter1.Fill(ds,"Client");
cutsReport.SetDataSource(ds);
crystalReportViewer.ReportSource = cutsReport;
I have tried doing it but shows all the records from the Client table
|
|
|
|
|
You need to use parameters. There are good examples at Business Objects. The have a .Net starters guide at http://www.businessobjects.com/jump/xi/default.asp[^] that was very helpful. If you also reference their knowledge base, they have many examples of how to set up running a report from within you app as you seem to be attempting.
|
|
|
|
|
Has anyone read the following book?
Pro .Net 1.1 Remoting, Reflection, and Threading
It looks like just the book i need, but i can't find a review (even by the publisher) anywhere on the web.
Comments would be appreciated.
Thanks,
Russ
|
|
|
|
|
How's the author? Maybe I've read the Italian translation.
___________________________________
Tozzi is right: Gaia is getting rid of us.
My Blog [ITA]
|
|
|
|
|
Pro .Net 1.1 Remoting, Reflection, and Threading
Syed Fahad Gilani, Mike Gillespie, James Hart, Benny Mathew, Sandra Gopikrishna, Andy Olsen
One of the reasons i asked was because there were so many authors, in the past i've found that books with this many people can be a bit incoherent. I suppose that comes down to how well it's editted really.
Thanks for replying,
Russ
|
|
|
|
|
Hello,
I have a little problem when saving my xml file.
I use an instance of System.Xml.Document.
I load an xml document file and edit this file with an application, then when I save it (doc.save("file.xml") ), I would like also the whitespaces being saved.
Exemple:
<element>
<subElement> </subElement>
</element>
It saves correctly the whitespaces, but when I read it again, the whitespaces are trimmed!
To prevent that, I would like to replace whitespaces by :   but on saving the xml writer encodes this sequence into : &#32; and therefore it is not interpreted as a whitespace anymore...
Any help would be really appreciated, thanks in advance!
-- modified at 10:12 Wednesday 28th September, 2005
|
|
|
|
|
I don't think you can get it to retain the whitespace when it's read. Special characters will not get interpreted as whitepsace either.
I'm curious, why would you want the whitespace in there? I can't think of a reason to do it.
You MIGHT be able to get away with putting in attributes into your nodes that specify how many spaces to put into the data when you retrieve the data. Something like:
<element>
<subElement wsPrefix=8 wsPostfix=3>mydata</subElement>
</element>
When you go to retrieve the element, read the wsPrefix and wsPostfix attributes and add the number of spaces to your data accordingly.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi, thanks for your idea, I will think about it.
The reason I need a white space is because I have some subElements that I want to concatenate
like "someData"+WHITESPACE+"someData".
for example:
<element>
<subElement type="data">someData</subElement>
<subElement type="caption"> </subElement>
<subElement type="data">someData</subElement>
</element>
I found this really weird that the xmlReader does not interpret one or more whitespace in the Innertext part of an element... don't you think so?
|
|
|
|
|
I have been trying to figure out a memory leak for quite some time. I've ignored what C# is supposedly taking care of but now that is the only thing I have left. And...I discovered something I'm confused about.
Add a new form to a project and drop some components on it. You will find
private System.ComponentModel.Container components = null;
and
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if(components != null)<br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose( disposing );<br />
}
But there will be no further reference to the use of components.
Therefore, when I dynamically create a form frmDialog(), do what I have to do, then Dispose() of the form, it fails the if(components != null) check and the components are never released. I even set the form to null (which I know I shouldn't do) but that still left the form defined. In the main form, frmDialog still exists as a defined object. In frmDialog() I add my own Dispose() calls for my classes and they show as undefined but every component of the form is still defined. I suspect that is why my memory is never released; because the form components haven't been released (showing <<undefined value="">>) the form can't release.
1) My understanding is "Don't do any maintenance within the #region Windows Form Designer generated code section so how do I get the components of the form into the variable components so they can be destroyed?
or
2) Is there a routine I can add to the Dispose() method to dispose of all the components by hand? Why would I have to do this?
Thanks.
|
|
|
|