Click here to Skip to main content
15,891,136 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: How to update a table Pin
cstrader2328-Sep-06 3:31
cstrader2328-Sep-06 3:31 
GeneralRe: How to update a table Pin
Dave Kreskowiak8-Sep-06 6:41
mveDave Kreskowiak8-Sep-06 6:41 
QuestionThe source file has changed Pin
KreativeKai7-Sep-06 2:12
professionalKreativeKai7-Sep-06 2:12 
AnswerRe: The source file has changed Pin
_mubashir7-Sep-06 21:31
_mubashir7-Sep-06 21:31 
AnswerRe: The source file has changed Pin
A*****11-Sep-06 13:51
A*****11-Sep-06 13:51 
GeneralRe: The source file has changed Pin
KreativeKai12-Sep-06 1:25
professionalKreativeKai12-Sep-06 1:25 
Questionlist view Pin
Hasan Jaffal7-Sep-06 1:59
Hasan Jaffal7-Sep-06 1:59 
AnswerRe: list view Pin
H@is@here7-Sep-06 11:14
H@is@here7-Sep-06 11:14 
Here is a class to sort a listview. Just pass the index of the column and the listview when creating a new instance of the class.

Public Class CompareListViewItems
Implements IComparer

Shared bSortDirection As Boolean = True
Dim sRoutineToUse As String = "String"
Dim lView As ListView 'the listview in question
Dim iColumn As Integer 'the column to sort
Dim lvCollection As ListView.ListViewItemCollection
Dim bSafeToSort As Boolean = False


Sub New(ByVal itemIndex As Integer, ByVal lvListView As ListView)
iColumn = itemIndex
lView = lvListView
bSortDirection = Not bSortDirection
lvCollection = New ListView.ListViewItemCollection(lvListView)
determineType()
End Sub

Private Function determineType() As Boolean

'There needs to be at least 2 elements to sort --
If (lView.Items.Count < 2) Then
bSafeToSort = False
Return False
End If

'If a value is Null, a subitem might not be added
If (checkForNull() = True) Then
bSafeToSort = False
Return False
End If

'If there are values in each element, lets determine the type
If (isItADate() = True) Then
sRoutineToUse = "Date"
ElseIf (isItANumber() = True) Then
sRoutineToUse = "Number"
Else
sRoutineToUse = "String"
End If

End Function

Private Function checkForNull() As Boolean

Dim lvTest As ListViewItem
Dim sItemContents As String

For Each lvTest In lvCollection
Try
If iColumn = 0 Then
sItemContents = lvTest.Text
Else
sItemContents = lvTest.SubItems(iColumn).Text
End If
Catch
Return True
End Try
Next

bSafeToSort = True
Return False 'we are good to go

End Function

Private Function isItADate() As Boolean
'-- Is it a date? --

Dim lvTest As ListViewItem 'assigned a new row
Dim oObjectToTest As Object 'recipient of the assignment
Dim sItemContents As String 'contents of the element

'-- Loop through each element
For Each lvTest In lvCollection


If iColumn = 0 Then
sItemContents = lvTest.Text
Else
sItemContents = lvTest.SubItems(iColumn).Text
End If

Try
oObjectToTest = CDate(sItemContents)
Catch
Return False
End Try

Next

Return True

End Function

Private Function isItANumber() As Boolean

Dim lvTest As ListViewItem 'assigned a new row
Dim oObjectToTest As Object 'recipient of the assignment
Dim sItemContents As String 'contents of the element

'-- Loop through each element
For Each lvTest In lvCollection

If iColumn = 0 Then
sItemContents = lvTest.Text
Else
sItemContents = lvTest.SubItems(iColumn).Text
End If

Try
oObjectToTest = CDbl(sItemContents)
Catch
Return False
End Try
Next

Return True

End Function


Function compare(ByVal oFirst As Object, ByVal oSecond As Object) As Integer _
Implements System.Collections.IComparer.Compare

If bSafeToSort = False Then Exit Function

Dim lvElement1 As ListViewItem = CType(oFirst, ListViewItem)
Dim lvElement2 As ListViewItem = CType(oSecond, ListViewItem)

If sRoutineToUse = "String" Then

If bSortDirection = True Then
If iColumn = 0 Then
Return String.Compare(lvElement1.Text, lvElement2.Text)
Else
Return String.Compare(lvElement1.SubItems(iColumn).Text, _
lvElement2.SubItems(iColumn).Text)
End If
Else
If iColumn = 0 Then
Return String.Compare(lvElement2.Text, lvElement1.Text)
Else
Return String.Compare(lvElement2.SubItems(iColumn).Text, _
lvElement1.SubItems(iColumn).Text)
End If
End If

ElseIf sRoutineToUse = "Number" Then

If bSortDirection = True Then
If iColumn = 0 Then
Return Math.Sign(CLng(lvElement1.Text - lvElement2.Text))
Else
Return Math.Sign(CLng(lvElement1.SubItems(iColumn).Text _
- lvElement2.SubItems(iColumn).Text))
End If
Else
If iColumn = 0 Then
Return Math.Sign(CLng(lvElement2.Text - lvElement1.Text))
Else
Return Math.Sign(CLng(lvElement2.SubItems(iColumn).Text _
- lvElement1.SubItems(iColumn).Text))
End If
End If
Else 'Its a date
If bSortDirection = True Then
If iColumn = 0 Then
Return Date.Compare(Date.Parse(lvElement1.Text), _
Date.Parse(lvElement2.Text))
Else
Return Date.Compare(Date.Parse(lvElement1.SubItems(iColumn).Text), _
Date.Parse(lvElement2.SubItems(iColumn).Text))
End If
Else
If iColumn = 0 Then
Return Date.Compare(Date.Parse(lvElement2.Text), _
Date.Parse(lvElement1.Text))
Else
Return Date.Compare(Date.Parse(lvElement2.SubItems(iColumn).Text), _
Date.Parse(lvElement1.SubItems(iColumn).Text))
End If
End If
End If

End Function
End Class
GeneralRe: list view [modified] Pin
Hasan Jaffal7-Sep-06 13:43
Hasan Jaffal7-Sep-06 13:43 
GeneralRe: list view Pin
Hasan Jaffal7-Sep-06 14:11
Hasan Jaffal7-Sep-06 14:11 
GeneralRe: list view Pin
H@is@here9-Sep-06 16:29
H@is@here9-Sep-06 16:29 
GeneralRe: list view Pin
slowbutsure2913-Sep-06 21:42
slowbutsure2913-Sep-06 21:42 
Questionhelp for atlas: cascading drop down from database? Pin
ii_noname_ii7-Sep-06 1:38
ii_noname_ii7-Sep-06 1:38 
AnswerRe: help for atlas: cascading drop down from database? Pin
ii_noname_ii7-Sep-06 2:24
ii_noname_ii7-Sep-06 2:24 
GeneralRe: help for atlas: cascading drop down from database? Pin
ii_noname_ii7-Sep-06 21:52
ii_noname_ii7-Sep-06 21:52 
QuestionExcel Dataset Datatype Pin
dwadasi7-Sep-06 1:31
dwadasi7-Sep-06 1:31 
Questiontelephonic data extraction from PBX using system defined funtion Pin
Pradip Kishore7-Sep-06 1:14
Pradip Kishore7-Sep-06 1:14 
Questionquestion in the use of the datagrid Pin
Hasan Jaffal7-Sep-06 0:48
Hasan Jaffal7-Sep-06 0:48 
AnswerRe: question in the use of the datagrid Pin
Tamimi - Code7-Sep-06 1:19
Tamimi - Code7-Sep-06 1:19 
GeneralRe: question in the use of the datagrid Pin
Hasan Jaffal7-Sep-06 1:22
Hasan Jaffal7-Sep-06 1:22 
AnswerRe: question in the use of the datagrid Pin
Tamimi - Code7-Sep-06 1:49
Tamimi - Code7-Sep-06 1:49 
GeneralRe: question in the use of the datagrid Pin
Hasan Jaffal7-Sep-06 2:14
Hasan Jaffal7-Sep-06 2:14 
GeneralRe: question in the use of the datagrid Pin
Tamimi - Code7-Sep-06 2:31
Tamimi - Code7-Sep-06 2:31 
GeneralRe: question in the use of the datagrid Pin
Hasan Jaffal7-Sep-06 14:05
Hasan Jaffal7-Sep-06 14:05 
QuestionProblem in Exporting Crystal Report to Excel Pin
mynameatif7-Sep-06 0:22
mynameatif7-Sep-06 0:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.