Skip to content

SyncfusionExamples/How-to-perform-hash-calculation-in-WinForms-DataGrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to perform hash calculation in WinForms DataGrid

WinForms DataGrid (SfDataGrid) does not provide direct support to perform the Hash calculation. You can perform the Hash calculation by customizing the CurrentCellValidated event with the SHA256 hash helper method.

//Event subscription
sfDataGrid1.CurrentCellValidated += OnCurrentCellValidated; 

//Event customization
private void OnCurrentCellValidated(object sender, CurrentCellValidatedEventArgs e)
{
     // Customize based on your requirement
     if (e.Column.MappingName == "Password")
     {
         //Get the current row
         var column = e.RowData as System.Data.DataRowView;
         //Set the Password column value as SHA256 hash
         column["Password"] = GetSHA256Hash((string)e.NewValue);
     }
}

//Helper method to get SHA256 hash
public static string GetSHA256Hash(string input)
{
     using (SHA256 sha256 = SHA256.Create())
     {
         // ComputeHash returns a byte array
         byte[] bytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(input)); 

         // Convert the byte array to a hexadecimal string
         StringBuilder builder = new StringBuilder();

         for (int i = 0; i < bytes.Length; i++)
         {
             builder.Append(bytes[i].ToString("x2")); // "x2" formats as a two-digit hexadecimal number
         }

         return builder.ToString();
     }
}

The screenshot below illustrates the hash calculation performed in the Password column,

Shows the Hash calculation

Take a moment to peruse the WinForms DataGrid - Cell Validation documentation, where you can find about cell validation with code examples.

About

How to perform hash calculation in WinForms DataGrid

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages