How to control Cell Value in DatagridView ...
-
Hi I want to check the value of DataGridView Cell , If the value of Cell Is empy or Null ! Here is My Code :
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
if (DataGridView1[i, j].Value == null || DataGridView1[i, j].Value.Equals(""))
{
MessageBox.Show("Some Cells in dataGridView Have not any Value");
return ;
}
else
{
tabControl1.TabPages.Add(TabPage2);
tabControl1.TabPages.Remove(TabPage1);
}
}}
I want to stay(stop) in TabPage1 if Some Value of Cell is Empty(Nul) But It does not Work Good ! Thanks !
-
Hi I want to check the value of DataGridView Cell , If the value of Cell Is empy or Null ! Here is My Code :
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
if (DataGridView1[i, j].Value == null || DataGridView1[i, j].Value.Equals(""))
{
MessageBox.Show("Some Cells in dataGridView Have not any Value");
return ;
}
else
{
tabControl1.TabPages.Add(TabPage2);
tabControl1.TabPages.Remove(TabPage1);
}
}}
I want to stay(stop) in TabPage1 if Some Value of Cell is Empty(Nul) But It does not Work Good ! Thanks !
-
Well, it should be: DataGridView1.Cells[i,j] You missed the Cells part. Now as a side note rant, why do you use those kind of variable names? DataGridiew1, TabControl1 ... If it's just a test then OK else kind of bad.
All the best, Dan
DataGridView1.Cells[i,j]
There is no Property "Cell" for DataGridView ! in any case , i want to say , how can we evaluate Cell Value , when It is Nul Or Empty ? I want to stop in TabPage1 when Cell Value is Empty ! thanks!
-
DataGridView1.Cells[i,j]
There is no Property "Cell" for DataGridView ! in any case , i want to say , how can we evaluate Cell Value , when It is Nul Or Empty ? I want to stop in TabPage1 when Cell Value is Empty ! thanks!
True, my bad, confused with another grid like control. dataGridView1.Rows[i].Cells[j] is the correct one. and your original one is ok too. [edit] On a closer look the logic is flawed as hell. I just took a quick glips at the code the first time. Don't activate tabs inside the for loops. Use a boolean, set it to true if something is empty, then ouside the loops do your thing such as showing messageboxes, activating tabcontrols or what have you based on that boolean logic.
All the best, Dan
-
True, my bad, confused with another grid like control. dataGridView1.Rows[i].Cells[j] is the correct one. and your original one is ok too. [edit] On a closer look the logic is flawed as hell. I just took a quick glips at the code the first time. Don't activate tabs inside the for loops. Use a boolean, set it to true if something is empty, then ouside the loops do your thing such as showing messageboxes, activating tabcontrols or what have you based on that boolean logic.
All the best, Dan
Yes , Thanks , But How can we give an Error and Stop In TabPage1? Regards!
-
Yes , Thanks , But How can we give an Error and Stop In TabPage1? Regards!
First, don't add/remove tabs. An easier way is to just activate the needed one. If you must, you could set the
Visible
property to false;bool error=false;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
if (DataGridView1[i, j].Value == null || DataGridView1[i, j].Value.Equals(""))
{
error=true;
break;
}
}
}if(error){
MessageBox.Show("something");
tabControl1.SelectTab("tabPage1");
}
else{ tabControl1.SelectTab("tabPage2");}Note that
SelectTab()
also supports a int as a parameter, e.g.TabCtrl.SelectTab(0);
All the best, Dan
-
First, don't add/remove tabs. An easier way is to just activate the needed one. If you must, you could set the
Visible
property to false;bool error=false;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
if (DataGridView1[i, j].Value == null || DataGridView1[i, j].Value.Equals(""))
{
error=true;
break;
}
}
}if(error){
MessageBox.Show("something");
tabControl1.SelectTab("tabPage1");
}
else{ tabControl1.SelectTab("tabPage2");}Note that
SelectTab()
also supports a int as a parameter, e.g.TabCtrl.SelectTab(0);
All the best, Dan
thanks in Advance !