|
Hi,
in the SortedList the keys are the one you are sorting after, so in this case you sort by username and not by department. You can also access the structures rather quick (binary search algorithm) via the username:
MyStructure structure = (MyStructure)sortedList["username1"];
You shouldn't use the SortedList in this case. You could just create a normal Array of your structures
(MyStructure[]) and sort it:
MyStructure[] structures = CalcStructures();
Array.Sort(structures, new MyStructComparator);
public class MyStructComparator : IComparer {
public int Compare(object obj1, object obj2) {
return ((MyStructure)obj1).Department.CompareTo(((MyStructure)obj2).Department);
}
}
Now you could also easiliy add as much properties as you like and sort them accordingly.
|
|
|
|
|
Pardon the newbie quesiton but isnt that c+ code?
|
|
|
|
|
My structure and my sorted list
Dim ipassinfo As New SortedList<br />
Public Structure user<br />
'Declare data members<br />
Public username As String<br />
Public department As String<br />
Public domestictotal As Decimal<br />
End Structure
Breaks up the line
adds it to my structure
adds the user name and the structure to the sorted list
fields = MyLine.Split(ControlChars.Tab) 'Or Convert.ToChar(Keys.Tab)<br />
<br />
<br />
'check to see if entrie already exists if not create it<br />
If ipassinfo(fields(2)) Is Nothing Then<br />
'loading the structure<br />
userinfo.username = fields(2)<br />
userinfo.department = "???"<br />
userinfo.domestictotal = fields(9)<br />
'adding the structure to the sortedlist under key username<br />
ipassinfo.Add((fields(2)), userinfo)<br />
Else<br />
' adds charges to total if allready exists<br />
userinfo.domestictotal = userinfo.domestictotal + fields(9)<br />
End If
|
|
|
|
|
Hi,
sorry about the C# code. Sometimes I just forget in which forum I am
I assume your code runs inside a loop over all entries.
After that (such that upassinfo is completely filled) place the following code:
Dim userarray As user()
ReDim userarray(ipassinfo.Values.Count)
ipassinfo.Values.CopyTo(userarray, 0)
userarray.Sort(userarray, New MyStructComparator)
Dim u As user
For Each u In userarray
'do something in sorted order
Next
Moreover you'll need this class:
Public Class MyStructComparator
Implements IComparer
Public Overridable Function Compare(ByVal x As Object,
ByVal y As Object) As Integer Implements IComparer.Compare
Return CType(x, user).department.CompareTo(CType(y, user).department)
End Function
End Class
|
|
|
|
|
Hi,
I have the following questions:
How can I write data in an Excel sheet and what is the proper object to display data in from an Excel sheet in a Windows form?
How can I insert input data from a form in an existing Microsoft Word document and how can I display the result?
Thank you.
-- modified at 2:05 Monday 1st May, 2006
|
|
|
|
|
hi ,
please i have a problem with date & time
as you know SQL Server have just a datetime type when i want to recuperate date from database in a textbox i got both the date&time in the same textbox ,but i want to get just the date or just the time
i hope you nderstood me
please if you did ell me how to do because i have a real problem with
thank you very much
try to be good if you can't be the best
|
|
|
|
|
VB or VB.NET?
Show the code that you have problems with, or noone can help you with it.
---
b { font-weight: normal; }
|
|
|
|
|
Mohammed Amine wrote: as you know SQL Server have just a datetime type
Actually it has a DATETIME and a SMALLDATETIME
Mohammed Amine wrote: i want to recuperate date from database in a textbox i got both the date&time in the same textbox ,but i want to get just the date or just the time
You can use DateTime.ToString()[^] to format the DateTime object.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
hi ,
please i added a picturebox to my application & it is behind all the controls of the form but i have labels on this picture & i wanna make this labels trensparent it was possible in vb.6 can you tell me how to do it in vb.net ??
thank you for your help
try to be good if you can't be the best
|
|
|
|
|
Set the BackColor property of Label to Transparent.
regards
Mubashir
|
|
|
|
|
thnx , but i don't think it will work because it is no transparent propriete in vb.net isn't it ??
may be i'm wrong i will seek for but i hoe to get an answear concerning vb.net i know this propriete exist in vb.6
thank you anyway for your help
try to be good if you can't be the best
|
|
|
|
|
Hi to all,
In IN WINDOW APPLICATION, I would like to know how can I print the page of the output window programically.
Thanks
Pankaj Garg
-- modified at 10:59 Sunday 30th April, 2006
|
|
|
|
|
|
Hi,
How I can copy any file to special directory >>
example:
file:- "red.avi" on the desktop.
directory:-" vedio" on the C.
How I can copy red.avi and put this copy in the C:\vedio
where become C:\vedio\red.avi
|
|
|
|
|
FileInfo class[^]. Look down the table, about the middle, on this page and you'll find a couple links to examples.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
tank you very very much >>
|
|
|
|
|
I am a complete newbie to programming and I need to work out how to use an on-screen keypad to enter values into a text-box. I'm not sure how to get the numbers to appear without erasing previously entered numbers. I know this is very basic but can anybody help?
|
|
|
|
|
Let's see the code your using. If your replacing everything in a TextBox when you hit a button, you're probably not assigning its Text property correctly.
I'd put this at an intermediate level task. On the surface, it looks really easy, but you have to have more than just a passing knowledge of how focus and selection works and how to track it properly.
If this input method was to be used in multiple places, it would be better written as it's own control.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi
I have form1 as MDI parent and i displayed the form2 as MDI child of form1 then i want to open form3 as MDI child of form1 from form2.
Please give me the solution.
Thnaks in advance.
MAP Tiger
Tiger Softwares
Software Designer and Developer
VB.NET, ASP.NET, VFP
|
|
|
|
|
This is not a good idea. The parent form should open all of it's child forms. Child forms should not be opening sibling child forms.
It can be done, but makes for spaghetti code:
Dim myForm As New Form3
myForm.MdiParent = Me.MdiParent
myForm.Show()
Dave Kreskowiak
Microsoft MVP - Visual Basic
-- modified at 11:06 Sunday 30th April, 2006
|
|
|
|
|
Well, thanks for this help n i got one more solution for that:
Dim myForm As New Form3
myForm.MdiParent = Me.ParentForm
myForm.Show()
MAP Tiger
Tiger Softwares
Software Designer and Developer
VB.NET, ASP.NET, VFP
|
|
|
|
|
Either way. They both point to the same parent.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
i am continuing my friend 's system, how can i find where is the declaration of this variables ,
loginID = txtUser.Text
because when i move the mouse there,i can see
public dim login ID as string
pls help me
|
|
|
|
|
Hi
Move the cursor to the variable for which you are searching the declaration and then just press "F12" function key and you will be on the point where that variable is declared.
bye
MAP Tiger
Tiger Softwares
Software Designer and Developer
VB.NET, ASP.NET, VFP
|
|
|
|
|
Hi All
The attached code fills a DataGrid for me from a CSV file. My App manipulates the data and represents it to the use. I then want to export to csv.
How is this done???
Private Sub FullImport(ByVal CommString As String, ByVal AnotherCommString As String)
Try
'Dim fi As New FileInfo(OpenFileDialog1.FileName)
Dim fi As New FileInfo(myFileName)
Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Text;Data Source=" & fi.DirectoryName
Dim objConn As New OleDbConnection(sConnectionString)
objConn.Open()
Dim objCmdSelect As New OleDbCommand(CommString & "[" & fi.Name & "]" & AnotherCommString, objConn)
Dim objAdapter1 As New OleDbDataAdapter
objAdapter1.SelectCommand = objCmdSelect
objAdapter1.Fill(objDataset1, "Import")
DataGrid1.DataSource = objDataset1.Tables(0).DefaultView
objConn.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
When people make you see red, be thankful your not colour blind.
|
|
|
|