Hi intoxicated-,
I recommend you use a DataGridView instead of DataGrid. It is very easy to set the password column display �***� You just need to handle the CellFormatting event. Here is a sample for your information:
Code Block
DataGridP
public partial class DGXML : Form
{
public DGXML()
{
InitializeComponent();
}
DataSet dsUsers = new DataSet();
private void DGXML_Load(object sender, EventArgs e)
{
if ((Thread.CurrentPrincipal.IsInRole("Administrator")))
{
// Grab list of Users
dsUsers.ReadXml(@"C:\1.xml");
// Bind the list of users to the Grid and display
dgUsers.CaptionText = "User Accounts";
dgUsers.DataSource = dsUsers.Tables[0];
this.dataGridView1.DataSource = dgUsers.DataSource = dsUsers.Tables[0];
this.dataGridView1.CellFormatting += new DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting);
}
else
{
MessageBox.Show("You must be a member of the Manager or Administrator's roles to " + "view username and password information", "Insufficient Permissions",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (this.dataGridView1.Columns[e.ColumnIndex].Name == "Password")
{
e.Value = "******";
}
}
private void btnSave_Click(object sender, EventArgs e)
{//save to the data to xml file
dsUsers.WriteXml(@"C:\1.xml", XmlWriteMode.WriteSchema);
}
}
To let the user edit in the DataGridView and write back to the XML file, you need the DataSet.WriteXml method. Check the above code sample.
Hope this helps. Best regards. Rong-Chun Zhang |