|
Hello Heath,
I give this a try first thing in the morning. Be back...
Tx Aad
Aad Slingerland
Zevenaar
The Netherlands
|
|
|
|
|
Sound like you might be doing what I was doing. I kept writing Console harness apps to get the output to track what's going on while developing until I found out about System.Diagnostics.Debug.WriteLine() . If you're using .Net Studio, it will display the information in the Output window. I use it in both windows forms or special classes that have no GUI interface. Sure beat the heck out of the test harnesses.
|
|
|
|
|
Working on the subject I found a even simpler way to create a console window from within a class module. It requires two p/invoke functions from kernel32 and than Console.WriteLine () will do! It goes like this...
bool b = AllocConsole ();
Console.WriteLine ("This...");
Console.WriteLine ("...That");
bool b = FreeConsole ();
Aad
Aad Slingerland
Zevenaar
The Netherlands
|
|
|
|
|
Please tell me there's an easier way. Here are a few examples of my recent pain:
It took me a day and a half of searching the Web, MSDN, and 6 books about C# before I found out there was an OpenFilaDialog class for asking the user which file they wanted my app to open.
It took me mere seconds to code a KeyDown event on my RichTextBox, and to figure out that I needed to use KeyEventArgs.Control to see if the control key was pressed, but it took several hours of searching to figure out I needed to compare Keys.L to KeyEventArgs.KeyCode to find out if <ctrl>L was pressed.
It took me hours of searching to find out that "Cursor.Current=Cursors.WaitCursor;" would change the mousepointer to the hourglass while my program retrieved from the database.
I am not stupid, I have been programming for over 25 years, in RPG, COBOL, TOTAL, ADS/O, PowerBuilder, and probably others along the way.
My whole department is going to come to me when they have the question: "In .NET, how do I...?", and I don't want to tell them I'll get back to them in a week.
I bought "C# for Experienced Programmers" by Deitel because it was the only book I could find that told me about the OpenFileDialog class. It did not help me with the other two situations I had.
I just have to beleive there is a better way...
|
|
|
|
|
My recommendation is to skim through the table of contents for the Class Library[^] to see what classes there are. I've seen many times where people are looking for something or end up writing something over when there was a class already for it. You wouldn't necessarily have to read about all the classes (at least the ones in which you're interested or the name is not self-explanitory enough) but just see what there is.
Also being familiar with the major abstract classes like System.Windows.Forms.Control is important. They define much of the functionality of their derivatives and understanding how they work is important. I also recommend that when you get more familiar with classes you see how they work under the covers using ildasm.exe from the .NET Framework SDK or a decompilers like .NET Reflector[^].
It's really just a case of getting to know the classes for such a large class library. Guessing also helps. If you're looking for an open file dialog, type "OpenFileDialog" (case not important) in the index of your Visual Studio Combined Help collection in the Visual Studio program group in yoru start menu. The local index is much easier to search than MSDN since there it's a keyword search, while and index like the combined collection (or the quarterly MSDN Library if you subscribe) is designed to help you be more efficient. When you get used to the class naming conventions of the .NET base class library (BCL) it gets easier to guess what a useful class name is. Type it in the index and read about 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]
|
|
|
|
|
To quote you: '...If you're looking for an open file dialog, type "OpenFileDialog"..'
Therein lies the crux of the problem. If I had known that it was called "OpenFileDialog" I wouldn't even have needed to search in the first place because autocomplete will tell me all about the methods, attributes, and events for that class. I searched for "openfile", "fileopen", "getfile", getfilename", "getfileopenname" (The function we use in PowerBuilder), "filechoose", "filename", and a hundred other search strings. No reasonable results came back from MSDN online, the WEB in general, or any books except the one I bought.
When I wanted to do the mousepointer thing, the first search string I entered was "cursor", but I got back 100 billion useless VB6, foxpro, and C++ answers for how to use database cursors. So I assumed I was on the wrong track and should search for "mouse", "mousepointer", "mouseicon", "pointer", etc. All to no avail.
Your idea about perusing the class library's table of contents is not a bad idea for a rainy day, but when I have a specific question about something in C#, there doesn't seem to be a resource available to me. IF MSDN online would let me filter my search PROPERLY, it might end up being the answer, but it's totally useless as it sits now.
I was hoping I could find a searchable reference resource (online or book) on C# specifically.
|
|
|
|
|
You need to limit your scope. If you simply search for "cursor" you will find lots of extraneous hits, but "mouse cursor" would've gotten rid of all those SQL database cursor documents and "mouse cursor in .NET" would've gotten you closer.
Using the Visual Studio Combined Collection is the best way, IMO, because - at least in the case of "cursor" typing it in the index (not search) would've given you relatively few - but more appropriate - hits. Indexes are more conceptual where keyword searches are almost always useless unless you get really specific.
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]
|
|
|
|
|
I don't have "Visual Studio Combined Help collection in the Visual Studio program group in your start menu".
Maybe that is the real problem here. Is it something I did not install? I have VS 2003 and .Net Framework 1.1.
I was relying too much on web searching, and not on searching specific help files on my own computer. I do have "MSDN Library for Visual Studio .NET 2003" on my start menu, but I had not seen that because it is so well hidden. Maybe all my complaining was for nought.
I searched it for "openfile" and it took me right to the OpenFileDialog class.
I searched for "mouse pointer", "mousepointer" and "mouse cursor", which didn't get me good results, but when I searched for "cursor" it went right to the Cursor and Cursors classes, which may have helped me, though the examples there were stupid.
I couldn't find a good search string for the Keys.L thing, but I think if I was on the KeyEventArgs class, I may have been able to figure out the Keys.L thing.
You may have opened a whole new world for me here.
|
|
|
|
|
You have to install the help collection after installing Visual Studio. What you have would be aggregated - along with third-party components some times - with the Visual Studio Combined Collection (or something similar to that; don't remember off-hand what the exact wording is).
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]
|
|
|
|
|
I do as you, but I often look at the functions and members of the class, and then I look at the index, that's really fast, after that I search msnd, that amost never give's me answers. I try to figure it out in another way insted.
I'm also a programmer that always write's my own code, with C#, it's a lot easier, becouse of the framework.
I'll need to learn the skill to use code of others...
The one and only Niklas Ulvinge aka IDK
|
|
|
|
|
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]
|
|
|
|