Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to get the original Value of an DataRow. The DataRow is containing a list of files with some information about them... The Rows where shown on a DataGridView...
Now I want to make the filenames renameable, for that purpose I need to get the Original Value of the edited cell(containing the name) and the current(after edit)...


This is my code until Now...
VB
Private Property Manager As MetroStyleManager
    Private WithEvents Data As New DataTable
    Private WithEvents Binding As New BindingSource

    Public Sub New(ByVal styleManager As MetroStyleManager)
        Me.Manager = styleManager
        InitializeComponent()
    End Sub

    ' Register Manager
    Private Sub Register_Manager_Load() Handles MyBase.Load
        Me.StyleManager = Manager
        Register_Tabs.ButtonStyleManager = Manager
        Load_Design()
        Load_Sources()
        Load_Registers()
End Sub

    ' Register Manager: Load Design
    Private Sub Load_Design()
        If My.Settings.Main_DarkMode Then
            Manager.Theme = MetroThemeStyle.Dark
            Manager.Style = MetroColorStyle.Blue
        Else
            Manager.Theme = MetroThemeStyle.Light
            Manager.Style = MetroColorStyle.Green
        End If
    End Sub

    ' Register Editor: Load DataSources
    Private Sub Load_Sources()
        Data.Columns.Add("Register Name", GetType(String))
        Data.Columns.Add("Enties", GetType(Int64))
        Data.Columns.Add("Last Edit", GetType(DateTime))
        Data.Columns.Add("Size (Mb)", GetType(String))
        Data.AcceptChanges()

        Binding.DataSource = Data
        Register_Grid.DataSource = Binding
        Register_Grid.Columns(0).ReadOnly = False
        Register_Grid.Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
        Register_Grid.Columns(1).ReadOnly = True
        Register_Grid.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader
        Register_Grid.Columns(2).ReadOnly = True
        Register_Grid.Columns(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.None
        Register_Grid.Columns(2).Width = 150
        Register_Grid.Columns(3).ReadOnly = True
        Register_Grid.Columns(3).AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader
    End Sub

' Register Manager: Load Registers
    Private Sub Load_Registers()
        Dim directoy = Application.StartupPath()
        For Each f In New IO.DirectoryInfo(directoy & "\register").GetFiles("*.csv")
            Dim name As String = f.Name
            Dim edit As String = f.LastWriteTime
            Dim entries As Int64 = File.ReadAllLines(f.FullName).Length - 1
            Dim size As Decimal = f.Length
            Data.Rows.Add(name, entries, edit, size.ToString("F3"))
        Next
    End Sub


Edit1 I would prefer using the RowStates to handel also deleting Rows (files have to get deleted too then)

What I have tried:

I searched for about 10 hours for an solution... And used many snippets, Nothing worked or returned any values except of "Nothing" values...

Most of the snippets were using the DataRowState or DataViewRowState Properties, but they seem to be not working with my DataTable...
Posted
Updated 30-May-20 2:41am
v2
Comments
Richard MacCutchan 30-May-20 8:19am    
You will need to save the original data somewhere when the user starts to edit the cell.
[no name] 30-May-20 8:28am    
You mean I should use the CellBeginEdit Event and store the Value in a Private Dim Var?
Richard MacCutchan 30-May-20 8:49am    
That is one way. But only you can really decide how best to do it.
[no name] 30-May-20 9:06am    
I would prefer the RowStates, because then I can read deleted Rows too :/
Richard MacCutchan 30-May-20 9:34am    
It does not matter what method you choose, as long as it does what you want. The only criterion is that you can identify when something is changing and thus save its current state. You may also want to consider what happens when something has been changed once and the user comes along and edits it again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900