c# - How to Convert a Byte Array to String for a DataGridView -


i have domain class user following properties (fields):

userid (int) username (nvarchar(25)) securepassword (varbinary(32)) salt (varbinary(32)) 

securepassword , salt store byte array length of 32 may have guessed. if set my

bindingsource.datasource = context.users.local.tobindinglist(); 

and my

datagridview.datasource = bindingsource; 

i’ll error telling me handle dataerror event gridview. once empty method securepassword , salt columns show [x] every row.

now, use linq render in anonymous type as:

 var data = u in context.users             select new             {                 u.userid,                 u.username,                 securepassword = bitconverter.tostring(u.securepassword),                 salt = bitconverter.tostring(u.salt)             }; 

but don’t want anonymous type. in wpf have written converter inherits ivalueconverter, doesn’t seem available in winforms. appreciated , welcomed.

use cellformatting event. like:

void datagridview_cellformatting(object sender, datagridviewcellformattingeventargs e) {     // 2 - salt, 3 - securepassword     if (e.columnindex == 2 || e.columnindex == 3)     {         if (e.value != null)         {             byte[] array = (byte[])e.value;             e.value = bitconverter.tostring(array);             e.formattingapplied = true;         }         else             e.formattingapplied = false;     } } 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -