|
Hi all,
i need to sort a listview based on the item tag property (as a category)
in fact, the listview is populated with a folder content from windows explorer.
when i click on the column header, i need to sort by name the folders and the after the files
Example :
the desired result
MyFolder
YourFolder
MyFile
YourFile
instead of
MyFile
MyFolder
YourFile
YourFolder
thanks for any idea, snippet code or a link
best regards
Fady Sayegh
|
|
|
|
|
The ListView class has, oh surprise, a Sort method. It offers a default sorting order, however it also provides a custom sorting order. MSDN holds the essential information, and one of my articles (see link in sig) deals with sorting in general, it does not mention ListView in particular.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi Luc,
thanks for your quick answer.
can you please provide me the link to your article.
sorry but i have clicked on the link [My Articles] but i didn't find any article about sorting issues
can you please redirect me to the right url.
thanks again for your help
Best regards
Fady Sayegh
|
|
|
|
|
just enter sorting and click the find button, that should do it.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Well your title "Sorting a Collection" only gives a small clue.
I must get a clever new signature for 2011.
|
|
|
|
|
Yeah, I spend most of my time searching for catchy, unexpected and mysterious titles, and yet I often fail at it.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Seriously?
see here[^]
There has always been a sort in list view.
It is amazing that you are asking such a fundamental question.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
In addition to Dalek Dave answer I am suggesting you to read these article [ Link1[^] and Link2[^] ] for more information
|
|
|
|
|
Hallo
I have two tables, let's say one Customers and one Orders, joined by CustomerID.
I represented each one by a datatable of its own in a dataset, and I created a DataRelation.
I would like to use them as datasource for one single BindingSource: is it possible?
|
|
|
|
|
I suppose it depends on the control. DataGrid(View)s can do that sort of thing, but it's generally not a good thing to use. I prefer a TreeView.
What would you want the control to do?
|
|
|
|
|
Hallo, thanks for reply.
The control will display data from the bindingsource and permit editing.
I'm currently using a dgv, but I'm actually aiming to use a treeview to list data informations, and a form to edit each single entry.
My main question is still: could a bindingsource be bound to a couple of joined tables?
|
|
|
|
|
My main response is still: it depends on the control.
|
|
|
|
|
Hi Guys,
does anyone know of a way / programme to convert Powershell scripts into C# code?
i have a short script that i need to convert and it is proving pretty tricky!
Many Thanks,
Phil
|
|
|
|
|
Hi,
Maybe seeing the original Powershell script could help
|
|
|
|
|
Sorry, i didn't want people to think i wanted them to do all my work for me.... but if your offering!
cls
$ErrorActionPreference = "SilentlyContinue"
$servers = Get-Content c:\Temp\servers.txt
foreach($srv in $servers)
{
try
{
$ID = New-Object System.Security.Principal.NTAccount("AccountName")
$SID = $ID.Translate([system.Security.Principal.SecurityIdentifier]).ToString()
$WMISDDL = "A;CI;CCWP;;;" + $SID
$WMISDDLPartialMatch = "A;\w*;\w+;;;" + $SID
$security = Get-WmiObject -ComputerName $srv -Namespace root -Class __SystemSecurity
$binarySD = @($null)
$result = $security.PsBase.InvokeMethod("GetSD",$binarySD)
write-host "`tConverting current permissions to SDDL format..."
$converter = new-object system.management.ManagementClass Win32_SecurityDescriptorHelper
$CurrentWMISDDL = $converter.BinarySDToSDDL($binarySD[0])
write-host "`tBuilding the new permissions..."
if (($CurrentWMISDDL.SDDL -match $WMISDDLPartialMatch) -and ($CurrentWMISDDL.SDDL -notmatch $WMISDDL))
{
$NewWMISDDL = $CurrentWMISDDL.SDDL -replace $WMISDDLPartialMatch, $WMISDDL
}
else
{
$NewWMISDDL = $CurrentWMISDDL.SDDL += "(" + $WMISDDL + ")"
}
# Convert SDDL back to Binary
write-host `t"Converting SDDL back into binary form..."
$WMIbinarySD = $converter.SDDLToBinarySD($NewWMISDDL)
$WMIconvertedPermissions = ,$WMIbinarySD.BinarySD
# Apply the changes
write-host "`tApplying changes..."
if($CurrentWMISDDL.SDDL.ToString().Contains($WMISDDL.ToString()))
{
write-host "`tCurrent WMI Permissions matches desired value..."
}
else
{
$result = $security.PsBase.InvokeMethod("SetSD",$WMIconvertedPermissions)
if($result='0'){write-host "`t`tApplied WMI Security complete."}
}
}
catch
{
Write-Host $Error[$Error.Count - 1].ToString()
}
}
Write-Host "`nFinished" -ForegroundColor DarkBlue
modified on Thursday, February 24, 2011 7:29 AM
|
|
|
|
|
Surround your code with <pre></pre> tags so it is readable.
I must get a clever new signature for 2011.
|
|
|
|
|
ok, i have done this now.
|
|
|
|
|
Philip Lane wrote: does anyone know of a way / programme to convert Powershell scripts into C# code?
Read a line of the script, and translate/convert it to C#. It's a manual proces where you interpret what the script should do, and write some code that does the same.
Philip Lane wrote: i have a short script that i need to convert and it is proving pretty tricky!
Can you point out where you're stuck with translating?
I are Troll
|
|
|
|
|
Hi Eddy,
the big problem is witht he casting. in PS it automatically decides what object type it needs to be but in C# it need to be specified. the code below compiles but line 11 errors saying - "Invalid parameter"
any help would be great thanks.
here is what i have so far:
InvokeMethodOptions imo = new InvokeMethodOptions();
imo.Timeout = new TimeSpan(0, 0, 0, 5);
NTAccount ID = new NTAccount(uName);
string SID = ID.Translate(typeof(SecurityIdentifier)).ToString();
string WMISDDL = "A;CI;CCWP;;;" + SID;
string WMISDDLPartialMatch = "A;\\w*;\\w+;;;" + SID;
ManagementClass security = new ManagementClass(new ManagementPath("\\\\" + server + "\\root\\Security:__SystemSecurity"));
object BinarySD = null;
ManagementBaseObject result = (ManagementBaseObject)security.InvokeMethod("GetSD", (ManagementBaseObject)BinarySD, imo);
ManagementClass converter = new ManagementClass("\\\\" + server + "\\root\\CIMV2:Win32_SecurityDescriptorHelper");
ManagementBaseObject CurrentWMISDDL = (ManagementBaseObject)converter.InvokeMethod("BinarySDToSDDL", (ManagementBaseObject) BinarySD, imo);
string NewWMISDDL;
if (CurrentWMISDDL.Properties["SDDL"].ToString() == WMISDDLPartialMatch && CurrentWMISDDL.Properties["SDDL"].ToString() != WMISDDL)
{
NewWMISDDL = CurrentWMISDDL.Properties["SDDL"].ToString().Replace(WMISDDLPartialMatch, WMISDDL);
}
else
{
NewWMISDDL = CurrentWMISDDL.Properties["SDDL"].ToString() + "(" + WMISDDL +")";
}
ManagementObject WMIBinarySD = (ManagementObject)converter.InvokeMethod("SDDLToBinarySD", new object[] { NewWMISDDL });
ManagementBaseObject WMIConvertedPerms = (ManagementBaseObject)WMIBinarySD.Properties["BinarySD"].Value;
if (CurrentWMISDDL.Properties["SDDL"].ToString().Contains(WMISDDL.ToString()))
{
Console.WriteLine("Current WMI permissions already match desired value.");
}
else
{
result = (ManagementObject)security.InvokeMethod("SetSD", new object[] { WMIConvertedPerms });
if ((Int32)result.GetPropertyValue("ReturnValue") == 0)
{
Console.WriteLine("Applied WMI security permissions.");
}
else
{
Console.WriteLine("Error applying permissions!");
}
}
}
catch (Exception exp)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Error: " + exp.Message.ToString());
Console.ResetColor();
}
Many Thanks,
Phil
|
|
|
|
|
That'd be this line;
ManagementBaseObject CurrentWMISDDL = (ManagementBaseObject)converter.InvokeMethod("BinarySDToSDDL", (ManagementBaseObject) BinarySD, imo);
Would that be the invocation of this[^] method? Seems to return an uint32 according to the documentation, taking two parameters.
Take care that you copy the correct version of all the references that the script is using.
I are Troll
|
|
|
|
|
tried that.. didn't work!
says it cant convert it, and other parts of the programme fail!
|
|
|
|
|
Philip Lane wrote: tried that.. didn't work! says it cant convert it
Compile-time or run-time?
Break up the statement into smaller pieces, so that you can check the assignment, the cast and the invoking of the function separately.
I are Troll
|
|
|
|
|
run-time.
i have tried what you suggested and it all looks fine!
|
|
|
|
|
Hi,
I am designing simple Calculator. And TextBox contains "300+500-10" values.
Kindly let me know, how may I calculate it from TextBox ? or Let me know another method.
Thank you
(Riaz)
|
|
|
|
|
Follow the link below:
http://www.codeproject.com/KB/recipes/MathieuMathParser.aspx?artkw=evaluate expression
Hope this will help.
|
|
|
|