|
|
Hi,
same as for any other collection you want to sort (array, ArrayList, ...):
write a class that implements IComparer and pass that to the Sort() method; on a LV that
happens through setting ListViewItemSorter property.
Implementing IComparer means providing a single method that takes two objects and returns an int:
int Compare (
Object x,
Object y
)
the int value should be negative, zero or positive depending on the sort order of the
two objects;
you would have to cast these objects to whatever type it is you have in the ListView.Items collection
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi!
I think one important point that might not be entirely obvious is that you sort by one column first and only have to return the result of the second column's comparison if the items to compare are the same in the first column!
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
I need to safely open a text file and send its contents to a textbox, if it doesnt exist i need to create it and then open it and show nothing in the textbox. I keep getting a "file is in use by another process" error.. here's my code..
TextReader fstream;
fp = filepath;
try
{
fstream = new StreamReader(fp);
}
catch (System.IO.FileNotFoundException)
{
File.CreateText(fp);
fstream = new StreamReader(fp);
}
bool done = false;
while(!done)
{
Alert = fstream.ReadLine();
if(Alert = null)
{
done = true;
else
{
textBox1.AppendText(Alert + "\r\n");
}
}
fstream.Close();
|
|
|
|
|
Dio22 wrote: I keep getting a "file is in use by another process" error
If another process has the file open in non "share" mode you will not be able to open it. Perhaps you have it open in some editor or something?
|
|
|
|
|
nope, nothing has it. error only happens when the file doesnt already exist. *shrug*
|
|
|
|
|
Dio22 wrote: error only happens when the file doesnt already exist. *shrug*
Yes that is because you are trying to create it in the catch() while you still have the active StreamReader in the try{} block.
|
|
|
|
|
Hi all,
Please could someone help me !!!!
I have a static class that I wish to use to create event handlers on controls.
I know the name of the class and method, I then want to create an instance of that class and assign one of its methods to be the event handler of the control. Bellow is roughly what I want to do (but it isn’t working )
object obj = Activator.CreateInstance("project1", vItem.Value.ToString());
pCtrl.TextChanged += new EventHandler(obj.GetType().GetMethod("MethodForEvent"));
The obj is wrapped instance and the getMethod returns null
Any Ideas ?
John
|
|
|
|
|
john34 wrote: Any Ideas ?
What are you trying to do? Is this some sort of plug-in solution?
|
|
|
|
|
Is there any significance to the use of the @ in a variable name (like @intx)?
Thanks.
|
|
|
|
|
The @ symbol is usually used for SQL Server parameters
SqlCommand.Parameters["@ID"].Value = 1234;<br />
<br />
CREATE PROC sp_MyProc @ID INT <br />
AS<br />
SELECT * FROM Table WHERE ID = @ID
The at symbol is also used to escape string literals
string path = @"C:\Program Files\Some Folder";
only two letters away from being an asset
|
|
|
|
|
sa_runner wrote: Is there any significance to the use of the @ in a variable name (like @intx)?
Using @ means that you can have a variable name that (sort of) matches a type name, e.g. object @object. In your code you can then refer to @object. It really doesn't seem to be good practice to me.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
In SQL yes, in C# no.
You can use it in c# as well, but the only thing that happens is that Intellisense does not work on this variable
-^-^-^-^-^-
no risk no funk ................... please vote ------>
|
|
|
|
|
@ is used to specify an identifier. It's mostly used to access members of third party classes that happen to be keywords in C#.
Example:
SomeComponent.@int x = new SomeComponent.@int();
---
single minded; short sighted; long gone;
|
|
|
|
|
Interesting, learn something all the time. Can't say as I've every seen this in use, and can't think of a reason why.
only two letters away from being an asset
|
|
|
|
|
reserved words are different in different languages. It's needed to allow assemblies written in Foo.net to always work in Bar.net without requiring any changes to the Foo.net source code because the author used a variable name that's reserved in Bar.net. MS tries to avoid any situation like this for the languages they officially provide (I've never actually seen it used myself), but the more languages supported the harder it becomes, and 3rd parties don't always have the same degree of foresight into cross language issues. This is an officially sanctioned work around.
--
If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.
|
|
|
|
|
That explains it, thanks.
only two letters away from being an asset
|
|
|
|
|
I appreciate all the answers. Thanks.
|
|
|
|
|
Hello Everyone,
I am a newbie to c# and have come from a very basic c/c++/perl background. I have a question as to how to set up an odbc connection in c# .net
Setting up the connection and doing what i have to do is no prob.
The problem lies when I want to define the connection from form1 (main form) or a public static class and use that connection for all child forms.
I wanted to give the connection a global scope, since it will be the only connection in my program. I tried defining it in a static class and setting each form's odbccommand.connection to equal the connection in the static class.
public class GlobalDB
{
public static OdbcConnection GDB;
static GlobalDB()
{
GDB.ConnectionString = "DRIVER={MySQL};SERVER=localhost;PORT=1111;DATABASE=test;UID=test;PWD=test";
}
}
From form 2:
this.SelectodbcCommand.Connection = GlobalDBNS.GlobalDB.GDB; //this.odbcConnection1; <<--- when called from local form all is good!
setting the connection = to my Global DB throws an exception I cannot catch.
Is this approach anywhere close to correct?
Should I just pass the connection to each of the child form's constructors?
Thanks in advance,
WT
PS what is the best book on c#.net out there? I want to get up to speed rather quickly.
|
|
|
|
|
You need to instantiate your GlobalDB class (just once!) somewhere before the first use of it. Without that the "global" connection won't exist.
Phil
The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.
|
|
|
|
|
Hi,
If anybody knows how to load up a Page object form a web address or has any idea about what could be done, please drop a message, even if you don't whant to...
Thx
|
|
|
|
|
What you are asking for is nothing that is normally done. What is it that you are trying to accomplish?
---
single minded; short sighted; long gone;
|
|
|
|
|
I have to extaract data by crawling true a website. I have to somehow get a Page class so I can access Page.Controls collection.
If I'm right, I have a hunch, with HttpWebRwsponse this could be done... still, I din't found a way yet...
|
|
|
|
|
You can only possibly create a Page object for a page if the page is in the same web application. If it's not, you can't.
The HttpWebRequest gets a response from which you can get the html code for the page as a string. The code contains only the html code that is generated, but no information about what server controls was used to generate the code, so you can't recreate any server controls from the response. You have to parse the html code to get the data from the page.
---
single minded; short sighted; long gone;
|
|
|
|
|
Thx for the response, it makes total sens... I hope I can make this somehow work , this tool will be used to trak down bugs by gathering CSS data...
Regards, Mogyi
|
|
|
|