Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Elegant Grid Tech Support » Cell Editing Collapse All
Subject Author Date
Dennis Mwape Oct 11, 2006 - 3:32 AM

Thanks for your quick response.However i tried your suggestion concerning cell editing and combobox binding however it does not seem to work.Here is the code snippet of the object I am trying to bind to the elegant grid and the code I have also included code in the form_load event
Please assist


Imports System.Threading
<Serializable()> _
Public Class Tax
Inherits BusinessBase
Private mPDCode As String = " "
Private mName As String = " "
Private mDebitAccountCode As String = " "
Private mCreditAccountCode As String = " "
Private mType As String = " "
Private mTaxBands As TaxBands = _
TaxBands.NewTaxBands
#Region " Utility Lists "
Private Shared mAccountCodes As AccountCodeList


Shared Sub New()
mAccountCodes = AccountCodeList.GetList

End Sub

Public Shared ReadOnly Property AccountCodes() As AccountCodeList
Get
Return mAccountCodes
End Get
End Property
#End Region



#Region " Business Properties and Methods "
Public ReadOnly Property PDCode() As String
Get
Return mPDCode
End Get
End Property
Public Property Name() As String
Get
Return mName
End Get
Set(ByVal Value As String)
If mName <> Value Then
If Not Thread.CurrentPrincipal.IsInRole("Administrator") Then
Throw New System.Security.SecurityException( _
"User not allowed to change/add payment and deduction codes")
Else
mName = Value
MarkDirty()
End If
End If

End Set
End Property
Public Property DebitAccountCode() As String
Get
Return AccountCodes.Item(mDebitAccountCode)
End Get
Set(ByVal Value As String)
If DebitAccountCode <> Value Then
If Not Thread.CurrentPrincipal.IsInRole("Administrator") Then
Throw New System.Security.SecurityException( _
"User not allowed to change/add payment and deduction codes")
Else
mDebitAccountCode = AccountCodes.Key(Value)
MarkDirty()
End If
End If

End Set
End Property
Public Property CreditAccountCode() As String
Get
Return AccountCodes.Item(mCreditAccountCode)
End Get
Set(ByVal Value As String)
If CreditAccountCode <> Value Then
If Not Thread.CurrentPrincipal.IsInRole("Administrator") Then
Throw New System.Security.SecurityException( _
"User not allowed to change/add payment and deduction codes")
Else
mCreditAccountCode = AccountCodes.Key(Value)
MarkDirty()
End If
End If

End Set
End Property
Public ReadOnly Property Type() As String
Get
Return mType
End Get
End Property

Public ReadOnly Property TaxBands() As TaxBands
Get
Return mTaxBands
End Get
End Property
Public Overrides ReadOnly Property IsValid() As Boolean
Get
Return MyBase.IsValid AndAlso mTaxBands.IsValid

End Get
End Property
Public Overrides ReadOnly Property IsDirty() As Boolean
Get
Return MyBase.IsDirty OrElse mTaxBands.IsDirty

End Get
End Property
#End Region

#Region "Shared functions "
Public Shared Function GetTax() As Tax
If Not Thread.CurrentPrincipal.IsInRole("Administrator") Then
Throw New System.Security.SecurityException( _
"User not allowed to update tax tables")
Else
Return CType(DataPortal.Fetch(New Criteria), Tax)
End If
End Function
#End Region

#Region " Constructors "
Private Sub New()

End Sub
#End Region

#Region "Criteria "
<Serializable()> _
Public Class Criteria

End Class
#End Region

#Region " Data Access "
Protected Overrides Sub Dataportal_Fetch(ByVal Criteria As Object)
Dim cn As New SqlConnection(DB("NuDB"))
Dim cm As New SqlCommand

cn.Open()

Try
With cm
.Connection = cn
.CommandType = CommandType.StoredProcedure
.CommandText = "getTax"

Dim dr As New SafedataReader(.ExecuteReader)
Try
dr.Read()
With dr
mPDCode = .GetString(0)
mName = .GetString(1)
mDebitAccountCode = .GetString(2)
mCreditAccountCode = .GetString(3)
mType = .GetString(4)

.NextResult()
mTaxBands = TaxBands.GetTaxBands(dr)
End With
Finally
dr.Close()
End Try
End With
MarkOld()
Finally
cn.Close()
End Try
End Sub
Protected Overrides Sub Dataportal_Update()
Dim cn As New SqlConnection(DB("NuDB"))
Dim cm As New SqlCommand

cn.Open()


Try
With cm
.Connection = cn
.CommandType = CommandType.StoredProcedure
.CommandText = "updateTax"
.Parameters.Add("@PDCode", mPDCode)
.Parameters.Add("@Name", mName)
.Parameters.Add("@DAcc", mDebitAccountCode)
.Parameters.Add("@CAcc", mCreditAccountCode)


.ExecuteNonQuery()
markold()


End With

Finally
cn.Close()
End Try
mTaxBands.Update(Me)
End Sub


#End Region

End Class


Imports System.Data.SqlClient
<Serializable()> _
Public Class TaxBands
Inherits BusinessCollectionBase
Protected Shadows allownew As Boolean = True
Protected Shadows AllowEdit As Boolean = True
Protected Shadows AllowRemove As Boolean = True


#Region " Business properties and methods "

Default Public ReadOnly Property Item(ByVal ID As Integer) As TaxBand
Get
Dim Child As TaxBand
For Each Child In list
If Child.ID = ID Then
Return Child
End If
Next
Return Nothing
End Get
End Property
Public Sub Remove(ByVal TaxBand As TaxBand)
list.Remove(TaxBand)
End Sub
Public Sub Remove(ByVal ID As Integer)
Dim T As TaxBand
For Each T In list
If T.ID = ID Then
Remove(T)
Exit For
End If
Next
End Sub
Private Sub AddTaxBand(ByVal TaxBand As TaxBand)
If Not Contains(TaxBand) Then
list.Add(TaxBand)
Else
Throw New Exception("This tax band has already been exists")
End If
End Sub
’ Public Sub NewTaxBand(ByVal LowerBand As Double, ByVal HigherBand As Double, ByVal TaxRate As Double)
’ AddTaxBand(TaxBand.NewTaxBand(LowerBand, HigherBand, TaxRate))
’End Sub
Public Sub NewTaxBand(ByVal TaxBand As TaxBand)
AddTaxBand(TaxBand)
End Sub
Protected Overrides Function OnAddNew() As Object
Return TaxBand.NewTaxBand
End Function

#End Region

#Region " Contains "

Public Overloads Function Contains(ByVal Item As TaxBand) As Boolean

Dim Child As TaxBand

For Each Child In List
If Child.Equals(Item) Then
Return True
End If
Next
Return False
End Function


#End Region

#Region " Shared factory Methods "

Friend Shared Function NewTaxBands() As TaxBands

Return New TaxBands

End Function

Friend Shared Function GetTaxBands(ByVal dr As SafedataReader) As TaxBands

Dim col As New TaxBands
col.fetch(dr)
Return col

End Function
#End Region

#Region " Constructors "

Private Sub New()
MarkAsChild()
End Sub

#End Region



#Region " Data Access "

Private Sub fetch(ByVal dr As SafedataReader)
While dr.Read()
List.Add(TaxBand.GetTaxBand(dr))
End While
End Sub
Friend Sub Update(ByVal Parent As Tax)
Dim Child As TaxBand
For Each Child In deletedlist
Child.Update(Parent)
Next
deletedlist.Clear()
For Each Child In list
Child.Update(Parent)
Next

End Sub


#End Region



End Class

Imports System.Data.SqlClient
Imports System.Threading
<Serializable()> _
Public Class TaxBand
Inherits BusinessBase
Private mID As Integer = 0
Private mLowerBand As Double = 0
Private mHigherBand As Double = 0
Private mTaxRate As Double = 0
Private mIsTrue As Boolean = True

#Region "Business properties and methods "
Public ReadOnly Property ID() As Integer
Get
Return mID
End Get
End Property
Public Property LowerBand() As String
Get
Return Format(mLowerBand, "#,##0.00")
End Get
Set(ByVal Value As String)
If mLowerBand <> CDbl(Value) Then
’ If Not Thread.CurrentPrincipal.IsInRole("Administrator") Then
’ Throw New System.Security.SecurityException( _
’ "User not allowed to update/add tax bands")
Else
mLowerBand = CDbl(Value)
markdirty()
End If
’ End If
End Set
End Property
Public Property HigherBand() As String
Get
Return Format(mHigherBand, "#,##0.00")
End Get
Set(ByVal Value As String)
If mHigherBand <> CDbl(Value) Then
’ If Not Thread.CurrentPrincipal.IsInRole("Administrator") Then
’ Throw New System.Security.SecurityException( _
’ "User not allowed to update/add tax bands")
Else
mHigherBand = CDbl(Value)
markdirty()
End If
’ End If
End Set
End Property
Public Property TaxRate() As String
Get
Return Format(mTaxRate, "0.00")
End Get
Set(ByVal Value As String)
If mTaxRate <> CDbl(Value) Then
’ If Not Thread.CurrentPrincipal.IsInRole("Administrator") Then
’Thr’ow New System.Security.SecurityException( _
’ "User not allowed to update/add tax bands")
Else
mTaxRate = CDbl(Value)
markdirty()
End If
’End If
End Set
End Property
Public ReadOnly Property IsTrue() As Boolean
Get
Return mIsTrue
End Get
End Property
#End Region

#Region " System.Object Overrides"

Public Overrides Function ToString() As String
Return mID.ToString
End Function

Public Overloads Function Equals(ByVal Item As TaxBand) As Boolean
Return mID.Equals(Item.ID)
End Function


Public Overloads Function GetHasCode() As Integer
Return mID.GetHashCode
End Function

#End Region

#Region " Shared Methods "
’ Friend Shared Function NewTaxBand(ByVal LowerBand As Double, _
’ ByVal HigherBand As Double, _
’ ByVal TaxRate As Double) As TaxBand
’ Return New TaxBand(LowerBand, HigherBand, TaxRate)
’ End Function

Friend Shared Function NewTaxBand() As TaxBand
Return New TaxBand
End Function
Friend Shared Function GetTaxBand( _
ByVal dr As SafedataReader) As TaxBand
Dim Obj As New TaxBand
Obj.fetch(dr)
Return Obj
End Function
#End Region

#Region " Constructors "


Private Sub New()
MarkAsChild()
End Sub
Private Sub New(ByVal LowerBand As Double, _
ByVal HigherBand As Double, _
ByVal TaxRate As Double)
mLowerBand = LowerBand
mHigherBand = HigherBand
mTaxRate = TaxRate
End Sub

#End Region

#Region " Data Access "

Private Sub fetch(ByVal dr As SafedataReader)
With dr
mID = .GetInt32(0)
mLowerBand = .GetDecimal(1)
mHigherBand = .GetDecimal(2)
mTaxRate = .GetDouble(3)
End With
MarkOld()
End Sub
Friend Sub Update(ByVal Parent As Tax)

Dim cn As New SqlConnection(DB("NuDB"))
Dim cm As New SqlCommand

cn.Open()

Try
With cm
.Connection = cn
.CommandType = CommandType.StoredProcedure
If Me.IsDeleted Then
If Not Me.IsNew Then
.CommandText = "deleteTaxBand"
.Parameters.Add("@ID", mID)

.ExecuteNonQuery()
End If
MarkNew()
Else
If Me.IsNew Then
.CommandText = "addTaxTable"
.Parameters.Add("@LBand", mLowerBand)
.Parameters.Add("@HBand", mHigherBand)
.Parameters.Add("@TaxRate", mTaxRate)

.ExecuteNonQuery()
markold()

Else
.CommandText = "updateTaxBand"
.Parameters.Add("@ID", mID)
.Parameters.Add("@LBand", mLowerBand)
.Parameters.Add("@HBand", mHigherBand)
.Parameters.Add("@TaxRate", mTaxRate)

.ExecuteNonQuery()
markold()

End If

End If

End With

Finally
cn.Close()
End Try

End Sub
#End Region


End Class



Private Sub frmLab12_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
mTax = Tax.GetTax
Dim mLoans As LoanCategories = _
LoanCategories.GetLoanCategories

With UGrid
Dim C As New Column
C.HeaderText = "Lower Band"
Dim C1 As New Column
C1.HeaderText = "Higher Band"
Dim C2 As New Column
C2.HeaderText = "Tax rate"
.Columns.AddRange(New Column() { _
C, C1, C2})

UGrid.Columns(0).CellType = GetType(TextCell)
UGrid.Columns(1).CellType = GetType(ComboBoxCell)
UGrid.Columns(2).CellType = GetType(CheckBoxCell)
.Columns.Item(0).DataPropertyName = "LowerBand"
.Columns.Item(1).MappingDataSource = mLoans
.Columns.Item(1).MappingDisplayDataMember = "LoanName"
.Columns.Item(1).MappingValueDataMember = "ID"
.Columns.Item(2).DataPropertyName = "IsTrue"
.DataSource = mTax.TaxBands
.FocusedCellColumn = .Columns.Item(0)
.EnsureVisibleVertically(.FocusedRowIndex)
.FocusedCell.StartEdit()


End With

End Sub

Technical Support Oct 12, 2006 - 6:09 AM

You did not say what actually does not work. Please provide more details about the exception or error. We can only guess that you cannot start cell editing because you may have missed one line in the form_load routine.

.DataSource = mTax.TaxBands
’insert this line to set focus on desired row
.FocusedDataSourceItem = mTax.TaxBands(0);
.FocusedCellColumn = .Columns.Item(0)
.EnsureVisibleVertically(.FocusedRowIndex)
.FocusedCell.StartEdit()
If this doesn’t help, please let us know more about the problem.