Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

DataGridView get unmasked content by GetClipboardContent

$
0
0

Hi all,

I have a datagridview that password in one of its cells and that passwords have been masked by below code:

private void dgvPassword_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
	try
	{
		if (e.ColumnIndex == 2 && e.Value != null)
		{
			dgvPassword.Rows[e.RowIndex].Tag = e.Value;
			e.Value = new String('*', e.Value.ToString().Length);
		}
	}
	catch (Exception ex)
	{
		MessageBox.Show(ex.Message);
	}
}

now when the content loads, the datagridview is able to mask the password with password char (*). 

but what i would like is when a user use the copy menu on ContextMenuStrip of that password column, it is able to unmask the password, copy the password and paste it anywhere with the original password.

So far the copy menu of the ContextMenuStrip has below codes, but it only copies the password char (*), so how can i get the unmasked password please:

internal static void CopyToClipboardWithHeaders(DataGridView _dgv, bool isHeaderIncluded)
{
	//Copy to clipboard
	if (isHeaderIncluded == true)
	{
		_dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
	}
	else
	{
		_dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
	}
	DataObject dataObj = _dgv.GetClipboardContent();
	if (dataObj != null)
	{
		Clipboard.SetDataObject(dataObj);
	}
}

I have tried to manipulate the dataObj, again it only got set with the password char (*).

Thanks

Andie.


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>