Please welcome me as am a new member.
I have a datagridview with 7 columns on it. all this are xml file which get loaded to the datagridview. my columns are are follow
Department , Employment , Permanent , contract , Fontsize.
- I have a xml file called employees which get loaded to my datagridview
- The user will capture the data from the column cells
- On Fontsize column. i want the user to enter only two numbers or one for incresing the font size of the current row.
- if the user enters fontsize of 10, the current cell rows will change the font size(which mean department,employment,permanent and contract will change their font size).
- the change will only happen on the current cell selected. e.g if you change for columnIndex 1. only column index row will change fontsize.
- I have do the validations for allowing only numbers, but i want it to take two numbers only.
How can i change my fontsize of column index based on the number entered. I know of font dialog but thats not how i want it to be, i have use it for other client project.
I got this example but it is not how i want it as it got style. i only need fontsize
WinForms DataGridView font size
my validations
private void Gridview_Output_CellEndEdit_1(object sender, DataGridViewCellEventArgs e)
{
try
{
#region this one validate the font number/ restrctions
int RowIndex = e.RowIndex;
int columnIndex = e.ColumnIndex;
if (e.ColumnIndex == 2)
{
bool validation = true;
if (Gridview_.Rows[RowIndex].Cells[columnIndex].Value != null && Gridview_.Rows[RowIndex].Cells[columnIndex].Value.ToString().Trim() != "")
{
string DataToValidate = Gridview_.Rows[RowIndex].Cells[columnIndex].Value.ToString();
foreach (char c in DataToValidate)
{
if (!char.IsDigit(c))
{
validation = false;
break;
}
}
if (validation == false)
{
MessageBox.Show("Font must be numbers only", "Error Message", MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
Gridview_.Rows[RowIndex].Cells[columnIndex].Value = "";
}
}
}
loading the file
XmlDocument doc = new XmlDocument();
doc.Load(Employee);
my gridview column indexes
Gridview_.Rows[i].Cells[1].Value.ToString(); // for Department
Gridview_.Rows[i].Cells[2].Value.ToString(); // for Employment
Gridview_.Rows[i].Cells[3].Value.ToString(); //for Permanent
Gridview_.Rows[i].Cells[4].Value.ToString(); //for Contract
Gridview_.Rows[i].Cells[5].Value.ToString(); //for Fontsize
Thanks for your help and i hope my question is constructive enough
Aucun commentaire:
Enregistrer un commentaire