Skip to content

Commit ac1ec19

Browse files
committed
Add validation for the FileExtension column during name association
Closes #1
1 parent d476593 commit ac1ec19

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

PatternFileMover/NameAssociationsForm.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ private void NameAssociationsForm_Load(object sender, EventArgs e)
2323

2424
dataGridView1.CellValidating += new DataGridViewCellValidatingEventHandler(dataGridView1_CellValidating);
2525
dataGridView1.DataSource = dataSource;
26+
dataGridView1.DefaultValuesNeeded += dataGridView1_DefaultValuesNeeded;
2627

2728
if (dataGridView1.Rows.Count > 0)
2829
{
@@ -99,6 +100,30 @@ private void dataGridView1_CellValidating(object sender, DataGridViewCellValidat
99100
e.Cancel = true;
100101
}
101102
}
103+
else if (dataGridView1.Columns[e.ColumnIndex].Name.Equals("FileExtension"))
104+
{
105+
if (string.IsNullOrEmpty(e.FormattedValue.ToString()))
106+
{
107+
dataGridView1.Rows[e.RowIndex].SetValues("*.*");
108+
}
109+
else if (
110+
e.FormattedValue.ToString() != "*.*" &&
111+
e.FormattedValue.ToString().Substring(0, 1) == "*"
112+
)
113+
{
114+
dataGridView1.Rows[e.RowIndex].Cells[3].Value = e.FormattedValue.ToString().Substring(1);
115+
}
116+
else if (
117+
e.FormattedValue.ToString().IndexOf(".") == -1
118+
) {
119+
dataGridView1.Rows[e.RowIndex].Cells[3].Value = "." + e.FormattedValue.ToString();
120+
}
121+
}
122+
}
123+
124+
private void dataGridView1_DefaultValuesNeeded(object sender, System.Windows.Forms.DataGridViewRowEventArgs e)
125+
{
126+
e.Row.Cells["FileExtension"].Value = "*.*";
102127
}
103128

104129
private void dataGridView1_UserAddedRow(object sender, DataGridViewRowEventArgs e)

0 commit comments

Comments
 (0)