Archive for September, 2008

.NET Multidimension Searchable Typed Lists (Generics)

September 20, 2008

using System;

using

System.Collections.Generic;

//Note: .NET 2 SP1

//The typed list class takes a single type as its class.

//You can search the list with Find(First)/FindAll/FindLast/FindIndex

//On the surface this means that you can only have one data dimension in the list

//ie. A string or int.

//

//This presents a problem for multi-dimensioned data

//Eg If you search folders media you want searchable information such as:

//- Filename/Type/Track/Album/Artist/Genre/Length(Time) etc

//

//The type can be a class though

//This way the list can be searched based upon one field of the class

//or even some combination of it.

///////////////////////////////////////////////////////////////////////////////

namespace DataSet

{

public class authorsD

{

public authorsD(string vname, int vage, string vFilename)

{

name = vname;

age = vage;

filename = vFilename;

}

public string name { get; set; }

public int age { get; set; }

public string filename { get; set; }

}

class Lists

{

public List<authorsD >menux = new List<authorsD>();

public void DoStuff()

{

//Add an individual to list;

menux.Add(

new authorsD("Fred", 28,"c:\\temp\\fred.txt"));

menux.Add(

new authorsD("Harry", 28, "c:\\temp\\harry.txt"));

//menux[0].name will return "Fred" etc

//Find first match for individual

Namesearchfor =

"Fred";

List<authorsD> author = menux.FindAll(findName);

//Get the author’s age

int authorAge;

//Expect a simgle result

if (author.Count == 1)

{

authorAge = author[0].age;

}

//Get the author’s filename

string authorFilename;

//Expect a simgle result

if (author.Count == 1)

{

authorFilename = author[0].filename;

}

//Can use original list directly by searching for an index

//Get the author’s age

int authorIndex = menux.FindLastIndex(findName);

//Can then use the index on the original list to acces the item’s properties

string authorName = menux[authorIndex].name ;

//Find all matching an age

Agesearchfor = 28;

List<authorsD> ageList = menux.FindAll(findAge);

//Could then load the List into a menu

}

//The following are predicate used by the List Find methods

string Namesearchfor = "";

// Search predicate returns true if name matches.

private bool findName(authorsD s)

{

if (s.name == Namesearchfor) return true;

else return false;

}

int Agesearchfor = 0;

// Search predicate returns true if age matches.

private bool findAge(authorsD s)

{

if (s.age == Agesearchfor) return true;

else return false;

}

}

}

Some more softare hints-1 Renaming forms

September 16, 2008
If you copy change the name of windows form in .NET (2008) by only changing the class name in the form code you might end up with an error to do with Disposing method.
[Remember that there are three aspects to a form created in .NET using its visual editor:
   -The visual form
   -The form code
  – The code behind the visual aspects of the form (normally hidden)
– Make sure that the form code still has teh class inheriting from forms
– Make sure that the code behind (that is the file where the disposing method is) has the same name space etc.
– Note that you can get into a bind here if you just copy a form from teh solution viewer and paste it into the same project.
  A bulk name change (or right click on the form name in code-Rename) will potentially change the name to the same thing in both forms

Some Vista hints x 3

September 9, 2008
(1) How do you action "Open Command Prompt Here" in Explorer as in XP Power Tools
Right click on the folder in teh right pane (not left) while holding down the shift key .. simple!
Bonus: Note that if you browse in explorer to a file share on another computer and do same, its creates a new nw drive mapping that is destroyed when the command window is closed.
 
(2) How do you open those folders under your user folder that it won’t let you into?  Eg The SendTo folder.
In the Run dialog (on the start menu) enter Shell:Sento
Others:
Put shell: in front
Local AppData
LocalAppDataLow
LocalizedResourcesDir
MAPIFolder
My Music
My Pictures
My Video
MyComputerFolder
NetHood
NetworkPlacesFolder
 
(3) How do you turn off teh machine barking at you everytime you want to do some priveledged action (even though you have admin rights) as adminisrator.
Run Control Panel, Explorer it, then serach on UMC, drill into where you can disable it.
 
Note that for something you need to e=run as administrator, which if is always required change the shortcust to runas admin.
 
Cheers

Hi there .. been a while

September 9, 2008
Been a bit busy since my last blog in June.
 
4 week leave with no emails and internet/computer access (except to book some hotel stays).
One week in Switzerland including a wedding.
A quick trip to St Moritz, Zermat .. up to the Mattahor, through Zurich; by train.  All good
 
Then a 16 day tour of Italy .. we’ve everywhere.
Highlights .. many:
See the tombs of Galileo and Michalangelo, statue of David, Rome!
Favourite plce/s Sorrento, Amalfy Coast, Sienna, Florence etc
 
I’ll upload some photos
 
Cheers