Page 1 of 1

Custom column in debtor contacts

PostPosted: Wed Oct 26, 2022 2:22 pm
by DannyC
I've just knocked up a fairly simple plugin which adds a datetime column to the grd.ContactNames grid. See plugin attached.

When I edit the field my issue is that I don't know how to make the debtors screen dirty so that save is enabled.
And also how do I make that particular row dirty - i.e how do I set the ChangeFlag property to true?

Re: Custom column in debtor contacts  Topic is solved

PostPosted: Wed Oct 26, 2022 6:31 pm
by Mike.Sheen
Listen to the grid changed event - if your new column changes, invoke the NotifyPropertyChanged method of the corresponding contact name in the business logic. That'll set the change flag on the contact name, the collection and bubble events up to the UI so it knows something has changed.

Attached does this - I also added an index to your custom table in the SQL script attached to the documents, because without it performance is likely to suffer with a lot of contacts.

I also got rid of your global grid declaration you were using - that would have issues with multiple debtor maintenance forms open at once, as each time a debtor maintenance form opens the grid variable you had would have been overwritten with the current forms contact names grid. Hilarity would have ensued.

You still have an issue in your save logic, but you probably don't need me to work out what that is, or need me to fix it.

Re: Custom column in debtor contacts

PostPosted: Wed Oct 26, 2022 6:43 pm
by SBarnes
When I edit the field my issue is that I don't know how to make the debtors screen dirty so that save is enabled.


You should be able to set the change flag on the debtor to true and then usually there is a function called CheckEditStatus on most forms including debtors, if its not publicly available there is an old expression fake it to you make it, just set the debtor name equal to the debtor name and that will make things detect the change.

And also how do I make that particular row dirty - i.e how do I set the ChangeFlag property to true?


You need to attach a change event to grdContactNames for example below is the one from Jiwa for the contact grid itself, yours should follow behind just looking for your column

Code: Select all
 Private Sub grdContactNames_Change(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.ChangeEventArgs)
        Dim TempString As String = ""
        Dim Title As String = ""
        Dim FirstName As String = ""
        Dim Surname As String = ""
        Dim Phone As String = ""
        Dim Mobile As String = ""
        Dim Fax As String = ""
        Dim Email As String = ""
        Dim LogonCode As String = ""
        Dim LogonPassword As String = ""

        If Debtor.IsReading = False Then
            With grdContactNames
                If e.Row >= 0 Then
                    TempString = .GridText(.ActiveSheet.Columns(e.Column).Tag, e.Row)
                    Dim Key As String = .GridText("Key", e.Row)
                    If Key.Length = 0 Then
                        Dim contactName As JiwaDebtors.ContactName = Manager.CollectionItemFactory.CreateCollectionItem(Of JiwaDebtors.ContactName)()
                        Select Case .ActiveSheet.Columns(e.Column).Tag
                            Case "Title"
                                contactName.Title = TempString
                            Case "FirstName"
                                contactName.FirstName = TempString
                            Case "Surname"
                                contactName.Surname = TempString
                            Case "Phone"
                                contactName.Phone = TempString
                            Case "Mobile"
                                contactName.Mobile = TempString
                            Case "Fax"
                                contactName.Fax = TempString
                            Case "Email"
                                contactName.EmailAddress = TempString
                            Case "LogonCode"
                                contactName.LogonCode = TempString
                            Case "LogonPassword"
                                contactName.LogonPassword = TempString
                        End Select
                        _Debtor.ContactNames.Add(contactName)
                    Else
                        Key = .GridText("Key", e.Row)
                        If Key.Trim.Length > 0 Then
                            Select Case .ActiveSheet.Columns(e.Column).Tag
                                Case "Title"
                                    _Debtor.ContactNames(Key).Title = TempString
                                Case "FirstName"
                                    _Debtor.ContactNames(Key).FirstName = TempString
                                Case "Surname"
                                    _Debtor.ContactNames(Key).Surname = TempString
                                Case "Phone"
                                    _Debtor.ContactNames(Key).Phone = TempString
                                Case "Mobile"
                                    _Debtor.ContactNames(Key).Mobile = TempString
                                Case "Fax"
                                    _Debtor.ContactNames(Key).Fax = TempString
                                Case "Email"
                                    _Debtor.ContactNames(Key).EmailAddress = TempString
                                Case "LogonCode"
                                    _Debtor.ContactNames(Key).LogonCode = TempString
                                Case "LogonPassword"
                                    _Debtor.ContactNames(Key).LogonPassword = TempString
                            End Select
                        End If
                    End If
                End If
            End With
        End If
    End Sub

Re: Custom column in debtor contacts

PostPosted: Wed Oct 26, 2022 6:53 pm
by SBarnes
Hmm, answers in stereo now :lol:

If you really wanted to to have a go at doing it the purist right way you could turn your table into a Jiwa collection item and then create a Jiwa collection class as well and keep that in the debtors generic object collection and pull it from there on the saves and reads and changes etc.

Re: Custom column in debtor contacts

PostPosted: Thu Oct 27, 2022 10:19 am
by DannyC
Appreciate the replies.

After I posed the question I was thinking about it a few hours later & realised I should just hook into the Changed event. Duh. Then I read Mike's plugin :D
Some nice information in there.