03 January 2013

Compare DatagridviewComboBox Value with TextBox Value in DataGridview using C#.net

"Compare DatagridviewComboBox Value with TextBox Value in DataGridview using C#.net"
private void button1_Click(object sender, EventArgs e)
{
DataGridViewComboBoxColumn column1 = (DataGridViewComboBoxColumn)dataGridView1.Columns[0];
foreach (string str in column1.Items)
{
if (str == textBox1.Text)
{
MessageBox.Show("Already Exists");
break;
}
}
}

02 January 2013

Compare Two Cell Values in Datagridview using C#.Net

private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
if (e.ColumnIndex == 2)
{
 int minValue = Convert.ToInt32(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["MinValue"].Value.ToString()); int maxValue = Convert.ToInt32(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["MaxValue"].Value.ToString()); bool chkValue = compareTwoCellValues(minValue, maxValue);
if (chkValue)
{
 dataGridView1.AllowUserToAddRows = false; dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["MaxValue"].Selected = true; chkValue = false;
}
 else
 {
 dataGridView1.AllowUserToAddRows = true; chkValue = false;
 }
}
}
bool statusofCompareValue;
bool compareTwoCellValues(int MinValue, int MaxValue)
{
 if (MinValue > MaxValue)
 {
 MessageBox.Show("Please enter greater than value"); statusofCompareValue = true;
 }
 else
 {
statusofCompareValue = false;
}
 return statusofCompareValue;
 }

01 January 2013

Display File Name path in ComboBox using C#.Net

"Display File Name path in Combobox using C#.Net"


addParentdirectoryFile Method
private void addParentdirectoryFile(string sourcePath)
{
string[] fileNames = Directory.GetFiles(sourcePath);
foreach (string str in fileNames)
{
comboBox1.Items.Add(str);
}
}
addChildDirectFiles Method
private void addChildDirectFiles(string sourcePath)
{
foreach (string subFolders in Directory.GetDirectories(sourcePath,"*",SearchOption.AllDirectories))
{
string[] subFolderfileNames = Directory.GetFiles(subFolders);
foreach (string fname in subFolderfileNames)
{
comboBox1.Items.Add(fname);
}
}
}
Call this method where you want:
addParentdirectoryFile();
addChildDirectFiles();