Solved

objectlistview sort problem

Posted on 2015-01-17
10
302 Views
Last Modified: 2015-01-25
I have an objectlistview on my form
I am sorting this listview by the column(1)

Sort code used is

ObjectListView1.Sort(olv1WOdds, SortOrder.Ascending)

this is connect to a timer with 5 sec refresh
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Runners.Clear()
        getRaceInfo(rc, rn)
        ObjectListView1.Sort(olv1WOdds, SortOrder.Ascending)
        getOdds()
        CloseAPI()
    End Sub

Open in new window

initial does not sort
 first refresh sorts
from second it does not sort

Screen Shots
Captured 11:14:53Captured 11:14:58Captured 11:15:03
Column being sorted WOdds

Does anyone have any advise
0
Comment
Question by:Jason
  • 5
  • 4
10 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 40555246
Please clarify what you mean by "objectlistview". Are you referring to this:  http://objectlistview.sourceforge.net/cs/index.html ?
0
 
LVL 32

Expert Comment

by:it_saige
ID: 40555401
Thats the one Kaufmed.

-saige-
0
 

Author Comment

by:Jason
ID: 40555504
As saige said
Thats the one any advise
@saige
Whats your thoughts buggered if i can work it out
This all stems for updating the listview records instead of clearing and repopulating
0
 
LVL 32

Expert Comment

by:it_saige
ID: 40555513
Generally when I am performing this type of function, I bind the data source of the control to a binding source and bind the data source of the binding source to a list of some sort (binding list is preferred if you are dynamically adding and removing objects from the list).  This way, you can handle the sort within the binding source itself.  And since a binding list supports PropertyChange and ListChange events out of the box, it will update the binding source whenever it (or one of it's object members property changes).

Unfortunately, I can't throw together a sample right this second.  But when I get time later, if this has not been answered, I'll whip up and example.

-saige-
0
 

Author Comment

by:Jason
ID: 40555542
That would be great
Thx
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 32

Accepted Solution

by:
it_saige earned 500 total points
ID: 40559963
Here is a sample implementation:

Form1.vb -
Imports BrightIdeasSoftware
Imports System.ComponentModel
Imports System.Reflection

Public Class Form1
	Private Races As SortableBindingList2(Of RaceInfo)
	Private IsSorting As Boolean = False
	Private TypedList As TypedObjectListView(Of RaceInfo)
	Private data As String = "OK Win Approximates 00:00:00" & vbCrLf _
	 & "SG,GOSFORD,4,STEVE BLYTH ELECTRICAL STAKE M,20081104,515,GOOD,OCAST,CLOSED,19:57:39" & vbCrLf _
	 & "3,10, , , ,19:57:00,19:58:11,19:57:22,19:56:37" & vbCrLf _
	 & "1,N,INSTANT GABBIE,PETER JOHNSON,1,0.0,10.30,11.00,7.70" & vbCrLf _
	 & "2,N,AMICA NIKITA,BARBARA CHENEY,2,0.0,25.80,24.90,29.00" & vbCrLf _
	 & "3,N,LAURIE'S STAR,LAWRENCE REFAL,3,0.0,2.30,2.10,3.20" & vbCrLf _
	 & "4,Y,ROCA BENNY,ROBERT WHITELA,4,0.0,0.01,0.01,0.01" & vbCrLf _
	 & "5,N,SPICEY SPY,LESLIE FLETCHE,5,0.0,16.00,17.90,12.30" & vbCrLf _
	 & "6,Y,ASHBY JEWEL,KEVIN ELLIOTT,6,0.0,0.01,0.01,0.01" & vbCrLf _
	 & "7,N,MUNDINE,HELEN SIMMONS,7,0.0,4.40,4.30,4.10" & vbCrLf _
	 & "8,N,MINER BRUSHES,WENDY BROWN,8,0.0,14.40,15.90,13.10" & vbCrLf _
	 & "9,Y,TURTLE NECK,WAYNE VANDERBU,0,0.0,0.01,0.01,0.01" & vbCrLf _
	 & "10,N,BOO BOO LEE,KRISTY SULTANA,4,0.0,3.80,4.30,3.20" & vbCrLf _
	 & "W, , , , , ,26507,22505,10795" & vbCrLf _
	 & "P, , , , , ,5101,4407,2921" & vbCrLf _
	 & "Q, , , , , ,2524,2197,1681" & vbCrLf _
	 & "E, , , , , ,1210,1095,816" & vbCrLf _
	 & "T, , , , , ,6998,6278,4823" & vbCrLf _
	 & "F, , , , , ,0,0,0" & vbCrLf _
	 & "D, , , , , ,0,0,0" & vbCrLf _
	 & "R, , , , , ,0,0,0" & vbCrLf _
	 & "4, , , , , ,0,0,0" & vbCrLf _
	 & "." & vbCrLf _
	 & ""

	Private Sub OnLoad(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
		Try
			Races = New SortableBindingList2(Of RaceInfo)
			RaceSource.DataSource = Races
			RunnerListViewData(data)
			ObjectListView1.DataSource = RaceSource
			TypedList = New TypedObjectListView(Of RaceInfo)(ObjectListView1)
			TypedList.GenerateAspectGetters()
			ObjectListView1.Sort(colWinOdds, SortOrder.Descending)
		Catch ex As Exception

		End Try
	End Sub

	Public Sub RunnerListViewData(ByVal data As String)
		Try
			Dim raceInfo As String() = data.Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
			Dim numRaces As Integer
			If raceInfo.Length > 3 Then
				With raceInfo(2)
					If Integer.TryParse(raceInfo(2).Split(New Char() {","c})(1), numRaces) Then
						For i = 3 To numRaces + 2
							With raceInfo(i)
								Dim parts As String() = raceInfo(i).Split(New Char() {","c})
								Dim info As New RaceInfo()
								If parts(0) Is Nothing OrElse Not Integer.TryParse(parts(0), info.Number) Then
									info = Nothing
								Else
									If parts(6) Is Nothing OrElse Not Decimal.TryParse(parts(6), info.WinOdds) Then
										info = Nothing
									End If
								End If
								If Not info Is Nothing Then
									AddHandler info.CheckChanged, AddressOf OnCheckChanged
									Races.Add(info)
								End If
							End With
						Next
					End If
				End With
			End If
		Catch ex As Exception

		End Try
	End Sub

	Private Sub OnCheckChanged(ByVal sender As Object, ByVal e As CheckChangedEventArgs)
		If TypeOf (sender) Is RaceInfo Then
			Dim data As RaceInfo = CType(sender, RaceInfo)
			Select Case e.PropertyName
				Case "Check1"
					If e.PropertyValue Then
						data.MM = "MM Calculation"
						data.PoolPercentage = 34.28
					Else
						data.MM = String.Empty
						data.PoolPercentage = 0.0
					End If
				Case "Check2"
					If e.PropertyValue Then
						data.MG = "MG Calculation"
						data.RunningPercentage = 52.16
					Else
						data.MG = String.Empty
						data.PoolPercentage = 0.0
					End If
				Case "Check3"
					If e.PropertyValue Then
						data.RM = "RM Calculation"
						data.UDiff = data.PoolPercentage - data.RunningPercentage
					Else
						data.RM = String.Empty
						data.UDiff = String.Empty
					End If
			End Select
		End If
	End Sub

	''' <summary>Handles the <see cref="E:Click" /> event.</summary>
	''' <param name="sender">The sender.</param>
	''' <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
	Private Sub OnClick(ByVal sender As Object, ByVal e As EventArgs) Handles btnReload.Click, btnClear.Click, btnEdit.Click
		If TypeOf sender Is Button Then
			Dim btn As Button = DirectCast(sender, Button)
			If btn.Equals(btnClear) Then
				ObjectListView1.RemoveObjects(Races)
			End If

			If btn.Equals(btnReload) Then
				ObjectListView1.SetObjects(Races)
			End If

			If btn.Equals(btnEdit) Then
				Dim editor As RaceData = Nothing
				Dim race As RaceInfo = Nothing
				If ObjectListView1.SelectedObject IsNot Nothing AndAlso TypeOf ObjectListView1.SelectedObject Is RaceInfo Then
					race = DirectCast(ObjectListView1.SelectedObject, RaceInfo)
				Else
					race = New RaceInfo() With {.Number = Races.Max(Function(item) item.Number) + 1}
				End If

				editor = New RaceData(race)
				If editor.ShowDialog() = DialogResult.OK Then
					If ObjectListView1.SelectedObject Is Nothing Then
						Races.Add(editor.Race)
					End If
				End If
				If ObjectListView1.PrimarySortColumn IsNot Nothing Then
					If ObjectListView1.PrimarySortOrder = SortOrder.Ascending Then
						RaceSource.Sort = String.Format("{0} DESC", ObjectListView1.PrimarySortColumn.AspectName)
						RaceSource.Sort = String.Format("{0} ASC", ObjectListView1.PrimarySortColumn.AspectName)
					ElseIf ObjectListView1.PrimarySortOrder = SortOrder.Descending Then
						RaceSource.Sort = String.Format("{0} ASC", ObjectListView1.PrimarySortColumn.AspectName)
						RaceSource.Sort = String.Format("{0} DESC", ObjectListView1.PrimarySortColumn.AspectName)
					End If
				End If
			End If
		End If
	End Sub

	Private Sub OnBeforeSorting(ByVal sender As Object, ByVal e As BeforeSortingEventArgs) Handles ObjectListView1.BeforeSorting
		If Not IsSorting Then
			IsSorting = True
			e.Handled = True
			RaceSource.Sort = String.Format("{0} {1}", e.ColumnToSort.AspectName, If(e.SortOrder = SortOrder.None, String.Empty, If(e.SortOrder = SortOrder.Ascending, "ASC", "DESC")))
			IsSorting = False
		End If
	End Sub

	Private Sub OnListChanged(ByVal sender As Object, ByVal e As ListChangedEventArgs) Handles RaceSource.ListChanged
		If ObjectListView1.PrimarySortColumn IsNot Nothing Then
			If ObjectListView1.PrimarySortOrder = SortOrder.Ascending Then
				ObjectListView1.Sort(ObjectListView1.PrimarySortColumn, SortOrder.Descending)
				ObjectListView1.Sort(ObjectListView1.PrimarySortColumn, SortOrder.Ascending)
			ElseIf ObjectListView1.PrimarySortOrder = SortOrder.Descending Then
				ObjectListView1.Sort(ObjectListView1.PrimarySortColumn, SortOrder.Ascending)
				ObjectListView1.Sort(ObjectListView1.PrimarySortColumn, SortOrder.Descending)
			End If
		End If
	End Sub
End Class

Public Class RaceInfo
#Region "Check Changed Event Handlers"
	Private ReadOnly _checkChangedEventHandlers As New List(Of CheckChangedEventHandler)
	Public Custom Event CheckChanged As CheckChangedEventHandler
		AddHandler(ByVal value As CheckChangedEventHandler)
			_checkChangedEventHandlers.Add(value)
		End AddHandler

		RemoveHandler(ByVal value As CheckChangedEventHandler)
			_checkChangedEventHandlers.Remove(value)
		End RemoveHandler

		RaiseEvent(ByVal sender As Object, ByVal e As CheckChangedEventArgs)
			For Each handler As CheckChangedEventHandler In _checkChangedEventHandlers
				Try
					handler.Invoke(sender, e)
				Catch ex As Exception
					Debug.WriteLine(String.Format("Exception while invoking event handler: {0}", ex))
				End Try
			Next
		End RaiseEvent
	End Event

	Protected Overridable Sub OnCheckChanged(ByVal sender As Object, ByVal e As CheckChangedEventArgs)
		RaiseEvent CheckChanged(sender, e)
	End Sub
#End Region

#Region "Private Fields"
	Private fCheck1 As Boolean
	Private fCheck2 As Boolean
	Private fCheck3 As Boolean
#End Region

#Region "Public Properties"
	Public Property Number() As Integer
	Public Property WinOdds() As Decimal
	Public Property PoolPercentage() As Decimal
	Public Property RunningPercentage() As Decimal
	Public Property MM() As String
	Public Property UDiff() As String
	Public Property MG() As String
	Public Property RM() As String
	Public Property Check1() As Boolean
		Get
			Return fCheck1
		End Get
		Set(ByVal value As Boolean)
			If Not value.Equals(fCheck1) Then
				fCheck1 = value
				RaiseEvent CheckChanged(Me, New CheckChangedEventArgs("Check1", Check1))
			End If
		End Set
	End Property
	Public Property Check2() As Boolean
		Get
			Return fCheck2
		End Get
		Set(ByVal value As Boolean)
			If Not value.Equals(fCheck2) Then
				fCheck2 = value
				RaiseEvent CheckChanged(Me, New CheckChangedEventArgs("Check2", Check2))
			End If
		End Set
	End Property
	Public Property Check3() As Boolean
		Get
			Return fCheck3
		End Get
		Set(ByVal value As Boolean)
			If Not value.Equals(fCheck3) Then
				fCheck3 = value
				RaiseEvent CheckChanged(Me, New CheckChangedEventArgs("Check3", Check3))
			End If
		End Set
	End Property
#End Region
End Class

<Serializable()> _
Public Class SortableBindingList2(Of T)
	Inherits BindingList(Of T)
	Private _isSorted As Boolean
	Private _dir As ListSortDirection = ListSortDirection.Ascending

	<NonSerialized()> _
	Private _sort As PropertyDescriptor = Nothing

	Sub New(ByVal list As ICollection(Of T))
		MyBase.New(CType(list, IList(Of T)))
	End Sub

	Sub New()
		MyBase.New()
	End Sub

#Region "BindingList<T> Public Sorting API"
	Public Sub Sort()
		ApplySortCore(_sort, _dir)
	End Sub

	Public Sub Sort(ByVal [property] As String)
		' Get the PD 

		_sort = FindPropertyDescriptor([property])

		' Sort 

		ApplySortCore(_sort, _dir)
	End Sub

	Public Sub Sort(ByVal [property] As String, ByVal direction As ListSortDirection)
		' Get the sort property 

		_sort = FindPropertyDescriptor([property])
		_dir = direction

		' Sort 

		ApplySortCore(_sort, _dir)
	End Sub
#End Region

#Region "BindingList<T> Sorting Overrides"
	Protected Overrides ReadOnly Property SortDirectionCore() As ListSortDirection
		Get
			Return _dir
		End Get
	End Property

	Protected Overrides ReadOnly Property SortPropertyCore() As PropertyDescriptor
		Get
			Return _sort
		End Get
	End Property

	Protected Overrides ReadOnly Property SupportsSortingCore() As Boolean
		Get
			Return True
		End Get
	End Property

	Protected Overrides Sub ApplySortCore(ByVal [property] As PropertyDescriptor, ByVal direction As ListSortDirection)
		Dim items As List(Of T) = TryCast(Me.Items, List(Of T))

		If (items IsNot Nothing) AndAlso ([property] IsNot Nothing) Then
			Dim pc As New PropertyComparer(Of T)([property], direction)
			items.Sort(pc)

			' Set sorted 

			_isSorted = True
			_sort = [property]
			_dir = direction
		Else
			' Set sorted 

			_isSorted = False
		End If

		' Let bound controls know they should refresh their views
		Me.OnListChanged(New ListChangedEventArgs(ListChangedType.Reset, -1))
	End Sub

	Protected Overrides ReadOnly Property IsSortedCore() As Boolean
		Get
			Return _isSorted
		End Get
	End Property

	Protected Overrides Sub RemoveSortCore()
		_isSorted = False
	End Sub
#End Region

#Region "BindingList<T> Private Sorting API"
	Private Function FindPropertyDescriptor(ByVal [property] As String) As PropertyDescriptor
		Dim pdc As PropertyDescriptorCollection = TypeDescriptor.GetProperties(GetType(T))
		Dim prop As PropertyDescriptor = Nothing

		If pdc IsNot Nothing Then
			prop = pdc.Find([property], True)
		End If

		Return prop
	End Function
#End Region

#Region "PropertyComparer<TKey>"
	Friend Class PropertyComparer(Of TKey)
		Implements System.Collections.Generic.IComparer(Of TKey)
		'
		'			* The following code contains code implemented by Rockford Lhotka:
		'			* //msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet01272004.asp" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet01272004.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet01272004.asp
		'			


		Private _property As PropertyDescriptor
		Private _direction As ListSortDirection

		Public Sub New(ByVal [property] As PropertyDescriptor, ByVal direction As ListSortDirection)
			_property = [property]
			_direction = direction
		End Sub

		Public Function Compare(ByVal xVal As TKey, ByVal yVal As TKey) As Integer Implements IComparer(Of TKey).Compare
			' Get property values 

			Dim xValue As Object = GetPropertyValue(xVal, _property.Name)
			Dim yValue As Object = GetPropertyValue(yVal, _property.Name)

			' Determine sort order 

			If _direction = ListSortDirection.Ascending Then
				Return CompareAscending(xValue, yValue)
			Else
				Return CompareDescending(xValue, yValue)
			End If
		End Function

		Public Function Equals(ByVal xVal As TKey, ByVal yVal As TKey) As Boolean
			Return xVal.Equals(yVal)
		End Function

		Public Function GetHashCode(ByVal obj As TKey) As Integer
			Return obj.GetHashCode()
		End Function

		' Compare two property values of any type 

		Private Function CompareAscending(ByVal xValue As Object, ByVal yValue As Object) As Integer
			Dim result As Integer

			' If values implement IComparer 

			If TypeOf xValue Is IComparable Then
				result = DirectCast(xValue, IComparable).CompareTo(yValue)
				' If values don't implement IComparer but are equivalent 

			ElseIf xValue.Equals(yValue) Then
				result = 0
			Else
				' Values don't implement IComparer and are not equivalent, so compare as string values 

				result = xValue.ToString().CompareTo(yValue.ToString())
			End If

			' Return result 

			Return result
		End Function

		Private Function CompareDescending(ByVal xValue As Object, ByVal yValue As Object) As Integer
			' Return result adjusted for ascending or descending sort order ie
			'				   multiplied by 1 for ascending or -1 for descending 

			Return CompareAscending(xValue, yValue) * -1
		End Function

		Private Function GetPropertyValue(ByVal value As TKey, ByVal [property] As String) As Object
			' Get property 

			Dim propertyInfo As PropertyInfo = value.[GetType]().GetProperty([property])

			' Return value 

			Return propertyInfo.GetValue(value, Nothing)
		End Function
	End Class
#End Region
End Class

Public Class SortableBindingList(Of T)
	Inherits BindingList(Of T)
	Private Property IsSorted As Boolean
	Private Property SortDirection As ListSortDirection
	Private Property SortProperty As PropertyDescriptor

	Protected Overrides ReadOnly Property SupportsSortingCore() As Boolean
		Get
			Return True
		End Get
	End Property

	Protected Overrides ReadOnly Property SortDirectionCore() As ListSortDirection
		Get
			Return _SortDirection
		End Get
	End Property

	Protected Overrides ReadOnly Property SortPropertyCore() As PropertyDescriptor
		Get
			Return _SortProperty
		End Get
	End Property

	Protected Overrides Sub ApplySortCore(ByVal [property] As PropertyDescriptor, ByVal direction As ListSortDirection)
		Dim items As List(Of T) = TryCast(Me.Items, List(Of T))
		If items Is Nothing Then
			IsSorted = False
		Else
			Dim comparer As New PropertyCompare(Of T)([property].Name, direction)
			items.Sort(comparer)
			IsSorted = True
			SortDirection = direction
			SortProperty = [property]
		End If
		OnListChanged(New ListChangedEventArgs(ListChangedType.Reset, -1))
	End Sub

	Protected Overrides ReadOnly Property IsSortedCore() As Boolean
		Get
			Return _IsSorted
		End Get
	End Property

	Protected Overrides Sub RemoveSortCore()
		_IsSorted = False
	End Sub

	Sub New(ByVal list As ICollection(Of T))
		MyBase.New(CType(list, IList(Of T)))
	End Sub

	Sub New()
		MyBase.New()
	End Sub

	Private Class PropertyCompare(Of T)
		Implements IComparer(Of T)

		Private Property PropertyInfo() As PropertyInfo
		Private Property SortDirection() As ListSortDirection
		Friend Sub New(ByVal [property] As String, ByVal direction As ListSortDirection)
			PropertyInfo = GetType(T).GetProperty([property])
			SortDirection = direction
		End Sub

		Friend Function Compare(ByVal x As T, ByVal y As T) As Integer Implements IComparer(Of T).Compare
			Return If(SortDirection = ListSortDirection.Ascending,
			  Comparer.[Default].Compare(PropertyInfo.GetValue(x, Nothing), PropertyInfo.GetValue(y, Nothing)),
			  Comparer.[Default].Compare(PropertyInfo.GetValue(y, Nothing), PropertyInfo.GetValue(x, Nothing)))
		End Function
	End Class
End Class

Public Delegate Sub CheckChangedEventHandler(ByVal sender As Object, ByVal e As CheckChangedEventArgs)

Public Class CheckChangedEventArgs
	Inherits EventArgs
	Private ReadOnly _propertyName As String
	Public ReadOnly Property PropertyName() As String
		Get
			Return _propertyName
		End Get
	End Property

	Private ReadOnly _propertyValue As Boolean
	Public ReadOnly Property PropertyValue() As Boolean
		Get
			Return _propertyValue
		End Get
	End Property

	Private Sub New()

	End Sub

	Public Sub New(ByVal PropertyName As String, ByVal PropertyValue As Boolean)
		_propertyName = PropertyName
		_propertyValue = PropertyValue
	End Sub
End Class

Open in new window


Form1.Designer.vb -
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
	Inherits System.Windows.Forms.Form

	'Form overrides dispose to clean up the component list.
	<System.Diagnostics.DebuggerNonUserCode()> _
	Protected Overrides Sub Dispose(ByVal disposing As Boolean)
		Try
			If disposing AndAlso components IsNot Nothing Then
				components.Dispose()
			End If
		Finally
			MyBase.Dispose(disposing)
		End Try
	End Sub

	'Required by the Windows Form Designer
	Private components As System.ComponentModel.IContainer

	'NOTE: The following procedure is required by the Windows Form Designer
	'It can be modified using the Windows Form Designer.  
	'Do not modify it using the code editor.
	<System.Diagnostics.DebuggerStepThrough()> _
	Private Sub InitializeComponent()
		Me.components = New System.ComponentModel.Container()
		Me.ObjectListView1 = New BrightIdeasSoftware.DataListView()
		Me.colNumber = CType(New BrightIdeasSoftware.OLVColumn(), BrightIdeasSoftware.OLVColumn)
		Me.colWinOdds = CType(New BrightIdeasSoftware.OLVColumn(), BrightIdeasSoftware.OLVColumn)
		Me.colPoolPercentage = CType(New BrightIdeasSoftware.OLVColumn(), BrightIdeasSoftware.OLVColumn)
		Me.colRunningPercentage = CType(New BrightIdeasSoftware.OLVColumn(), BrightIdeasSoftware.OLVColumn)
		Me.colMM = CType(New BrightIdeasSoftware.OLVColumn(), BrightIdeasSoftware.OLVColumn)
		Me.colUDiff = CType(New BrightIdeasSoftware.OLVColumn(), BrightIdeasSoftware.OLVColumn)
		Me.colMG = CType(New BrightIdeasSoftware.OLVColumn(), BrightIdeasSoftware.OLVColumn)
		Me.colRM = CType(New BrightIdeasSoftware.OLVColumn(), BrightIdeasSoftware.OLVColumn)
		Me.colCheck1 = CType(New BrightIdeasSoftware.OLVColumn(), BrightIdeasSoftware.OLVColumn)
		Me.colCheck2 = CType(New BrightIdeasSoftware.OLVColumn(), BrightIdeasSoftware.OLVColumn)
		Me.colCheck3 = CType(New BrightIdeasSoftware.OLVColumn(), BrightIdeasSoftware.OLVColumn)
		Me.btnClear = New System.Windows.Forms.Button()
		Me.btnReload = New System.Windows.Forms.Button()
		Me.btnEdit = New System.Windows.Forms.Button()
		Me.RaceSource = New System.Windows.Forms.BindingSource(Me.components)
		CType(Me.ObjectListView1, System.ComponentModel.ISupportInitialize).BeginInit()
		CType(Me.RaceSource, System.ComponentModel.ISupportInitialize).BeginInit()
		Me.SuspendLayout()
		'
		'ObjectListView1
		'
		Me.ObjectListView1.AllColumns.Add(Me.colNumber)
		Me.ObjectListView1.AllColumns.Add(Me.colWinOdds)
		Me.ObjectListView1.AllColumns.Add(Me.colPoolPercentage)
		Me.ObjectListView1.AllColumns.Add(Me.colRunningPercentage)
		Me.ObjectListView1.AllColumns.Add(Me.colMM)
		Me.ObjectListView1.AllColumns.Add(Me.colUDiff)
		Me.ObjectListView1.AllColumns.Add(Me.colMG)
		Me.ObjectListView1.AllColumns.Add(Me.colRM)
		Me.ObjectListView1.AllColumns.Add(Me.colCheck1)
		Me.ObjectListView1.AllColumns.Add(Me.colCheck2)
		Me.ObjectListView1.AllColumns.Add(Me.colCheck3)
		Me.ObjectListView1.AllowColumnReorder = True
		Me.ObjectListView1.AllowDrop = True
		Me.ObjectListView1.AlternateRowBackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(240, Byte), Integer), CType(CType(220, Byte), Integer))
		Me.ObjectListView1.BackColor = System.Drawing.SystemColors.Window
		Me.ObjectListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.colNumber, Me.colWinOdds, Me.colPoolPercentage, Me.colRunningPercentage, Me.colMM, Me.colUDiff, Me.colMG, Me.colRM, Me.colCheck1, Me.colCheck2, Me.colCheck3})
		Me.ObjectListView1.Cursor = System.Windows.Forms.Cursors.Default
		Me.ObjectListView1.DataSource = Nothing
		Me.ObjectListView1.EmptyListMsg = "This list is empty."
		Me.ObjectListView1.FullRowSelect = True
		Me.ObjectListView1.Location = New System.Drawing.Point(13, 13)
		Me.ObjectListView1.Name = "ObjectListView1"
		Me.ObjectListView1.OwnerDraw = True
		Me.ObjectListView1.Size = New System.Drawing.Size(655, 237)
		Me.ObjectListView1.TabIndex = 0
		Me.ObjectListView1.UseAlternatingBackColors = True
		Me.ObjectListView1.UseCompatibleStateImageBehavior = False
		Me.ObjectListView1.View = System.Windows.Forms.View.Details
		'
		'colNumber
		'
		Me.colNumber.AspectName = "Number"
		Me.colNumber.Groupable = False
		Me.colNumber.HeaderTextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colNumber.Text = "Race #"
		Me.colNumber.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colNumber.Width = 70
		'
		'colWinOdds
		'
		Me.colWinOdds.AspectName = "WinOdds"
		Me.colWinOdds.Groupable = False
		Me.colWinOdds.HeaderTextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colWinOdds.Text = "Win Odds"
		Me.colWinOdds.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
		Me.colWinOdds.Width = 70
		'
		'colPoolPercentage
		'
		Me.colPoolPercentage.AspectName = "PoolPercentage"
		Me.colPoolPercentage.Groupable = False
		Me.colPoolPercentage.HeaderTextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colPoolPercentage.Text = "Pool %"
		Me.colPoolPercentage.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
		Me.colPoolPercentage.Width = 70
		'
		'colRunningPercentage
		'
		Me.colRunningPercentage.AspectName = "RunningPercentage"
		Me.colRunningPercentage.Groupable = False
		Me.colRunningPercentage.HeaderTextAlign = System.Windows.Forms.HorizontalAlignment.Right
		Me.colRunningPercentage.Text = "Running %"
		Me.colRunningPercentage.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
		Me.colRunningPercentage.Width = 70
		'
		'colMM
		'
		Me.colMM.AspectName = "MM"
		Me.colMM.Groupable = False
		Me.colMM.HeaderTextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colMM.Text = "MM"
		Me.colMM.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colMM.Width = 70
		'
		'colUDiff
		'
		Me.colUDiff.AspectName = "UDiff"
		Me.colUDiff.Groupable = False
		Me.colUDiff.HeaderTextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colUDiff.Text = "UDiff"
		Me.colUDiff.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colUDiff.Width = 70
		'
		'colMG
		'
		Me.colMG.AspectName = "MG"
		Me.colMG.Groupable = False
		Me.colMG.HeaderTextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colMG.Text = "MG"
		Me.colMG.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colMG.Width = 70
		'
		'colRM
		'
		Me.colRM.AspectName = "RM"
		Me.colRM.Groupable = False
		Me.colRM.HeaderTextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colRM.Text = "RM"
		Me.colRM.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colRM.Width = 70
		'
		'colCheck1
		'
		Me.colCheck1.AspectName = "Check1"
		Me.colCheck1.CheckBoxes = True
		Me.colCheck1.Groupable = False
		Me.colCheck1.HeaderTextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colCheck1.Text = "1"
		Me.colCheck1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colCheck1.Width = 30
		'
		'colCheck2
		'
		Me.colCheck2.AspectName = "Check2"
		Me.colCheck2.CheckBoxes = True
		Me.colCheck2.Groupable = False
		Me.colCheck2.HeaderTextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colCheck2.Text = "2"
		Me.colCheck2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colCheck2.Width = 30
		'
		'colCheck3
		'
		Me.colCheck3.AspectName = "Check3"
		Me.colCheck3.CheckBoxes = True
		Me.colCheck3.Groupable = False
		Me.colCheck3.HeaderTextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colCheck3.Text = "3"
		Me.colCheck3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
		Me.colCheck3.Width = 30
		'
		'btnClear
		'
		Me.btnClear.Location = New System.Drawing.Point(512, 270)
		Me.btnClear.Name = "btnClear"
		Me.btnClear.Size = New System.Drawing.Size(75, 23)
		Me.btnClear.TabIndex = 1
		Me.btnClear.Text = "Clear"
		Me.btnClear.UseVisualStyleBackColor = True
		'
		'btnReload
		'
		Me.btnReload.Location = New System.Drawing.Point(593, 270)
		Me.btnReload.Name = "btnReload"
		Me.btnReload.Size = New System.Drawing.Size(75, 23)
		Me.btnReload.TabIndex = 2
		Me.btnReload.Text = "Reload"
		Me.btnReload.UseVisualStyleBackColor = True
		'
		'btnEdit
		'
		Me.btnEdit.Location = New System.Drawing.Point(431, 270)
		Me.btnEdit.Name = "btnEdit"
		Me.btnEdit.Size = New System.Drawing.Size(75, 23)
		Me.btnEdit.TabIndex = 3
		Me.btnEdit.Text = "Add/Edit Races"
		Me.btnEdit.UseVisualStyleBackColor = True
		'
		'RaceSource
		'
		'
		'Form1
		'
		Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
		Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
		Me.ClientSize = New System.Drawing.Size(681, 305)
		Me.Controls.Add(Me.btnEdit)
		Me.Controls.Add(Me.btnReload)
		Me.Controls.Add(Me.btnClear)
		Me.Controls.Add(Me.ObjectListView1)
		Me.Name = "Form1"
		Me.Text = "Form1"
		CType(Me.ObjectListView1, System.ComponentModel.ISupportInitialize).EndInit()
		CType(Me.RaceSource, System.ComponentModel.ISupportInitialize).EndInit()
		Me.ResumeLayout(False)

	End Sub
	Friend WithEvents ObjectListView1 As BrightIdeasSoftware.DataListView
	Friend WithEvents colNumber As BrightIdeasSoftware.OLVColumn
	Friend WithEvents colRunningPercentage As BrightIdeasSoftware.OLVColumn
	Friend WithEvents colMM As BrightIdeasSoftware.OLVColumn
	Friend WithEvents colUDiff As BrightIdeasSoftware.OLVColumn
	Friend WithEvents colMG As BrightIdeasSoftware.OLVColumn
	Friend WithEvents colRM As BrightIdeasSoftware.OLVColumn
	Friend WithEvents colCheck1 As BrightIdeasSoftware.OLVColumn
	Friend WithEvents colCheck2 As BrightIdeasSoftware.OLVColumn
	Friend WithEvents colCheck3 As BrightIdeasSoftware.OLVColumn
	Friend WithEvents colPoolPercentage As BrightIdeasSoftware.OLVColumn
	Friend WithEvents colWinOdds As BrightIdeasSoftware.OLVColumn
	Friend WithEvents btnClear As System.Windows.Forms.Button
	Friend WithEvents btnReload As System.Windows.Forms.Button
	Friend WithEvents RaceSource As System.Windows.Forms.BindingSource
	Friend WithEvents btnEdit As System.Windows.Forms.Button

End Class

Open in new window


RaceData.vb -
Public Class RaceData
	Private ReadOnly fRace As RaceInfo

	Public ReadOnly Property Race() As RaceInfo
		Get
			Return fRace
		End Get
	End Property

	''' <summary>Prevents a default instance of the <see cref="RaceData"/> class from being created.</summary>
	Private Sub New()
		Me.New(New RaceInfo())
	End Sub

	Public Sub New(ByRef Race As RaceInfo)
		InitializeComponent()

		If Race Is Nothing Then
			fRace = New RaceInfo()
		Else
			fRace = Race
		End If

		NumberTextBox.DataBindings.Add(New Binding("Text", fRace, "Number", True, DataSourceUpdateMode.OnPropertyChanged))
		WinOddsTextBox.DataBindings.Add(New Binding("Text", fRace, "WinOdds", True, DataSourceUpdateMode.OnPropertyChanged))
		PoolPercentageTextBox.DataBindings.Add(New Binding("Text", fRace, "PoolPercentage", True, DataSourceUpdateMode.OnPropertyChanged))
		RunningPercentageTextBox.DataBindings.Add(New Binding("Text", fRace, "RunningPercentage", True, DataSourceUpdateMode.OnPropertyChanged))
		MMTextBox.DataBindings.Add(New Binding("Text", fRace, "MM", True, DataSourceUpdateMode.OnPropertyChanged))
		UDiffTextBox.DataBindings.Add(New Binding("Text", fRace, "UDiff", True, DataSourceUpdateMode.OnPropertyChanged))
		MGTextBox.DataBindings.Add(New Binding("Text", fRace, "MG", True, DataSourceUpdateMode.OnPropertyChanged))
		RMTextBox.DataBindings.Add(New Binding("Text", fRace, "RM", True, DataSourceUpdateMode.OnPropertyChanged))
	End Sub

	Private Sub OnClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click, btnCancel.Click
		If TypeOf sender Is Button Then
			Dim btn As Button = DirectCast(sender, Button)
			If btn.Equals(btnOK) Then
				DialogResult = DialogResult.OK
			End If

			If btn.Equals(btnCancel) Then
				DialogResult = DialogResult.Cancel
			End If
			Close()
		End If
	End Sub
End Class

Open in new window


RaceData.Designer.vb -
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class RaceData
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
		Dim NumberLabel As System.Windows.Forms.Label
		Dim WinOddsLabel As System.Windows.Forms.Label
		Dim PoolPercentageLabel As System.Windows.Forms.Label
		Dim RunningPercentageLabel As System.Windows.Forms.Label
		Dim MMLabel As System.Windows.Forms.Label
		Dim UDiffLabel As System.Windows.Forms.Label
		Dim MGLabel As System.Windows.Forms.Label
		Dim RMLabel As System.Windows.Forms.Label
		Me.NumberTextBox = New System.Windows.Forms.TextBox()
		Me.WinOddsTextBox = New System.Windows.Forms.TextBox()
		Me.PoolPercentageTextBox = New System.Windows.Forms.TextBox()
		Me.RunningPercentageTextBox = New System.Windows.Forms.TextBox()
		Me.MMTextBox = New System.Windows.Forms.TextBox()
		Me.UDiffTextBox = New System.Windows.Forms.TextBox()
		Me.MGTextBox = New System.Windows.Forms.TextBox()
		Me.RMTextBox = New System.Windows.Forms.TextBox()
		Me.btnOK = New System.Windows.Forms.Button()
		Me.btnCancel = New System.Windows.Forms.Button()
		NumberLabel = New System.Windows.Forms.Label()
		WinOddsLabel = New System.Windows.Forms.Label()
		PoolPercentageLabel = New System.Windows.Forms.Label()
		RunningPercentageLabel = New System.Windows.Forms.Label()
		MMLabel = New System.Windows.Forms.Label()
		UDiffLabel = New System.Windows.Forms.Label()
		MGLabel = New System.Windows.Forms.Label()
		RMLabel = New System.Windows.Forms.Label()
		Me.SuspendLayout()
		'
		'NumberLabel
		'
		NumberLabel.AutoSize = True
		NumberLabel.Location = New System.Drawing.Point(70, 15)
		NumberLabel.Name = "NumberLabel"
		NumberLabel.Size = New System.Drawing.Size(47, 13)
		NumberLabel.TabIndex = 1
		NumberLabel.Text = "Number:"
		'
		'WinOddsLabel
		'
		WinOddsLabel.AutoSize = True
		WinOddsLabel.Location = New System.Drawing.Point(60, 41)
		WinOddsLabel.Name = "WinOddsLabel"
		WinOddsLabel.Size = New System.Drawing.Size(57, 13)
		WinOddsLabel.TabIndex = 3
		WinOddsLabel.Text = "Win Odds:"
		'
		'PoolPercentageLabel
		'
		PoolPercentageLabel.AutoSize = True
		PoolPercentageLabel.Location = New System.Drawing.Point(28, 67)
		PoolPercentageLabel.Name = "PoolPercentageLabel"
		PoolPercentageLabel.Size = New System.Drawing.Size(89, 13)
		PoolPercentageLabel.TabIndex = 5
		PoolPercentageLabel.Text = "Pool Percentage:"
		'
		'RunningPercentageLabel
		'
		RunningPercentageLabel.AutoSize = True
		RunningPercentageLabel.Location = New System.Drawing.Point(9, 93)
		RunningPercentageLabel.Name = "RunningPercentageLabel"
		RunningPercentageLabel.Size = New System.Drawing.Size(108, 13)
		RunningPercentageLabel.TabIndex = 7
		RunningPercentageLabel.Text = "Running Percentage:"
		'
		'MMLabel
		'
		MMLabel.AutoSize = True
		MMLabel.Location = New System.Drawing.Point(89, 119)
		MMLabel.Name = "MMLabel"
		MMLabel.Size = New System.Drawing.Size(28, 13)
		MMLabel.TabIndex = 9
		MMLabel.Text = "MM:"
		'
		'UDiffLabel
		'
		UDiffLabel.AutoSize = True
		UDiffLabel.Location = New System.Drawing.Point(83, 145)
		UDiffLabel.Name = "UDiffLabel"
		UDiffLabel.Size = New System.Drawing.Size(34, 13)
		UDiffLabel.TabIndex = 11
		UDiffLabel.Text = "UDiff:"
		'
		'MGLabel
		'
		MGLabel.AutoSize = True
		MGLabel.Location = New System.Drawing.Point(90, 171)
		MGLabel.Name = "MGLabel"
		MGLabel.Size = New System.Drawing.Size(27, 13)
		MGLabel.TabIndex = 13
		MGLabel.Text = "MG:"
		'
		'RMLabel
		'
		RMLabel.AutoSize = True
		RMLabel.Location = New System.Drawing.Point(90, 197)
		RMLabel.Name = "RMLabel"
		RMLabel.Size = New System.Drawing.Size(27, 13)
		RMLabel.TabIndex = 15
		RMLabel.Text = "RM:"
		'
		'NumberTextBox
		'
		Me.NumberTextBox.Location = New System.Drawing.Point(123, 12)
		Me.NumberTextBox.Name = "NumberTextBox"
		Me.NumberTextBox.ReadOnly = True
		Me.NumberTextBox.Size = New System.Drawing.Size(120, 20)
		Me.NumberTextBox.TabIndex = 2
		'
		'WinOddsTextBox
		'
		Me.WinOddsTextBox.Location = New System.Drawing.Point(123, 38)
		Me.WinOddsTextBox.Name = "WinOddsTextBox"
		Me.WinOddsTextBox.Size = New System.Drawing.Size(120, 20)
		Me.WinOddsTextBox.TabIndex = 4
		'
		'PoolPercentageTextBox
		'
		Me.PoolPercentageTextBox.Location = New System.Drawing.Point(123, 64)
		Me.PoolPercentageTextBox.Name = "PoolPercentageTextBox"
		Me.PoolPercentageTextBox.Size = New System.Drawing.Size(120, 20)
		Me.PoolPercentageTextBox.TabIndex = 6
		'
		'RunningPercentageTextBox
		'
		Me.RunningPercentageTextBox.Location = New System.Drawing.Point(123, 90)
		Me.RunningPercentageTextBox.Name = "RunningPercentageTextBox"
		Me.RunningPercentageTextBox.Size = New System.Drawing.Size(120, 20)
		Me.RunningPercentageTextBox.TabIndex = 8
		'
		'MMTextBox
		'
		Me.MMTextBox.Location = New System.Drawing.Point(123, 116)
		Me.MMTextBox.Name = "MMTextBox"
		Me.MMTextBox.Size = New System.Drawing.Size(120, 20)
		Me.MMTextBox.TabIndex = 10
		'
		'UDiffTextBox
		'
		Me.UDiffTextBox.Location = New System.Drawing.Point(123, 142)
		Me.UDiffTextBox.Name = "UDiffTextBox"
		Me.UDiffTextBox.Size = New System.Drawing.Size(120, 20)
		Me.UDiffTextBox.TabIndex = 12
		'
		'MGTextBox
		'
		Me.MGTextBox.Location = New System.Drawing.Point(123, 168)
		Me.MGTextBox.Name = "MGTextBox"
		Me.MGTextBox.Size = New System.Drawing.Size(120, 20)
		Me.MGTextBox.TabIndex = 14
		'
		'RMTextBox
		'
		Me.RMTextBox.Location = New System.Drawing.Point(123, 194)
		Me.RMTextBox.Name = "RMTextBox"
		Me.RMTextBox.Size = New System.Drawing.Size(120, 20)
		Me.RMTextBox.TabIndex = 16
		'
		'btnOK
		'
		Me.btnOK.Location = New System.Drawing.Point(87, 220)
		Me.btnOK.Name = "btnOK"
		Me.btnOK.Size = New System.Drawing.Size(75, 23)
		Me.btnOK.TabIndex = 17
		Me.btnOK.Text = "OK"
		Me.btnOK.UseVisualStyleBackColor = True
		'
		'btnCancel
		'
		Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
		Me.btnCancel.Location = New System.Drawing.Point(168, 220)
		Me.btnCancel.Name = "btnCancel"
		Me.btnCancel.Size = New System.Drawing.Size(75, 23)
		Me.btnCancel.TabIndex = 18
		Me.btnCancel.Text = "Cancel"
		Me.btnCancel.UseVisualStyleBackColor = True
		'
		'RaceData
		'
		Me.AcceptButton = Me.btnOK
		Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
		Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
		Me.CancelButton = Me.btnCancel
		Me.ClientSize = New System.Drawing.Size(255, 252)
		Me.Controls.Add(Me.btnCancel)
		Me.Controls.Add(Me.btnOK)
		Me.Controls.Add(RMLabel)
		Me.Controls.Add(Me.RMTextBox)
		Me.Controls.Add(MGLabel)
		Me.Controls.Add(Me.MGTextBox)
		Me.Controls.Add(UDiffLabel)
		Me.Controls.Add(Me.UDiffTextBox)
		Me.Controls.Add(MMLabel)
		Me.Controls.Add(Me.MMTextBox)
		Me.Controls.Add(RunningPercentageLabel)
		Me.Controls.Add(Me.RunningPercentageTextBox)
		Me.Controls.Add(PoolPercentageLabel)
		Me.Controls.Add(Me.PoolPercentageTextBox)
		Me.Controls.Add(WinOddsLabel)
		Me.Controls.Add(Me.WinOddsTextBox)
		Me.Controls.Add(NumberLabel)
		Me.Controls.Add(Me.NumberTextBox)
		Me.Name = "RaceData"
		Me.Text = "Add or Edit Races"
		Me.ResumeLayout(False)
		Me.PerformLayout()

	End Sub
	Friend WithEvents NumberTextBox As System.Windows.Forms.TextBox
	Friend WithEvents WinOddsTextBox As System.Windows.Forms.TextBox
	Friend WithEvents PoolPercentageTextBox As System.Windows.Forms.TextBox
	Friend WithEvents RunningPercentageTextBox As System.Windows.Forms.TextBox
	Friend WithEvents MMTextBox As System.Windows.Forms.TextBox
	Friend WithEvents UDiffTextBox As System.Windows.Forms.TextBox
	Friend WithEvents MGTextBox As System.Windows.Forms.TextBox
	Friend WithEvents RMTextBox As System.Windows.Forms.TextBox
	Friend WithEvents btnOK As System.Windows.Forms.Button
	Friend WithEvents btnCancel As System.Windows.Forms.Button
End Class

Open in new window


Produces the following output -Initial startup.Selecting Race number 6 and hitting add edit.We changed the win odd's to 3.04.  When we press ok, the list should automatically resort to reflect the new value location.List reordered.  (I manually selected the affected row to highlight it).-saige-
0
 

Author Comment

by:Jason
ID: 40560619
@saige
When you populate the listview after the change is it through an update method or is it through a clear listview an repopular the whole listview
0
 
LVL 32

Expert Comment

by:it_saige
ID: 40560682
Neither...  Since the ObjectListView is now a DataListView -Capture.JPGI can bind a datasource to it.  I then utilize a BindingSource and bind the list of objects (as a SortableBindingList) -Capture.JPGTo the datasource of the BindingSource.

So now, when I add, remove or update any of the items in the SortableBindingList, they in turn (by way of events) alert the BindingSource to this change.  The binding source then alerts the ObjectListView to the changes in the list.

So in direct answer to your question, when btnEdit is clicked (the Add/Edit button), the method first checks to see if an item is selected in the ObjectListView.  If an item is selected it gets the selected object and casts it to a RaceInfo.  Otherwise it creates a new RaceInfo setting the Number to the next avaialable number based on the max number + 1 in the current list of RaceInfo objects.
				Dim editor As RaceData = Nothing
				Dim race As RaceInfo = Nothing
				If ObjectListView1.SelectedObject IsNot Nothing AndAlso TypeOf ObjectListView1.SelectedObject Is RaceInfo Then
					race = DirectCast(ObjectListView1.SelectedObject, RaceInfo)
				Else
					race = New RaceInfo() With {.Number = Races.Max(Function(item) item.Number) + 1}
				End If

Open in new window

Then what happens is that a new RaceData form is created and opened based on the RaceInfo object.  If you edit any of the fields, they are updated directly on the RaceInfo object.  If you click Ok then the method checks to see if an item is selected in the ObjectListView (a dirty way of doing this) to see if the RaceInfo in the RaceData form represents a new row on an edited row.  If it is a new RaceInfo, we add it to the list (which in turn alerts the BindingSource that the list has changed).
				editor = New RaceData(race)
				If editor.ShowDialog() = DialogResult.OK Then
					If ObjectListView1.SelectedObject Is Nothing Then
						Races.Add(editor.Race)
					End If
				End If

Open in new window

As a sanity check, we go on ahead and resort the list based on the last selected PrimarySortColumn and the PrimarySortOrder (this is done twice because the ObjectListView will not resort if the sort column and sort order have not been changed since the last sort operation)-
				If ObjectListView1.PrimarySortColumn IsNot Nothing Then
					If ObjectListView1.PrimarySortOrder = SortOrder.Ascending Then
						RaceSource.Sort = String.Format("{0} DESC", ObjectListView1.PrimarySortColumn.AspectName)
						RaceSource.Sort = String.Format("{0} ASC", ObjectListView1.PrimarySortColumn.AspectName)
					ElseIf ObjectListView1.PrimarySortOrder = SortOrder.Descending Then
						RaceSource.Sort = String.Format("{0} ASC", ObjectListView1.PrimarySortColumn.AspectName)
						RaceSource.Sort = String.Format("{0} DESC", ObjectListView1.PrimarySortColumn.AspectName)
					End If
				End If
			End If

Open in new window

-saige-
0
 

Author Comment

by:Jason
ID: 40560767
Thks heaps ill check it out tonight
0
 

Author Closing Comment

by:Jason
ID: 40569676
Thks
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now