Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to control Cell Value in DatagridView ...

How to control Cell Value in DatagridView ...

Scheduled Pinned Locked Moved C#
tutorial
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nassimnastaran
    wrote on last edited by
    #1

    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 !

    D 1 Reply Last reply
    0
    • N nassimnastaran

      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 !

      D Offline
      D Offline
      Dan Mos
      wrote on last edited by
      #2

      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

      N 1 Reply Last reply
      0
      • D Dan Mos

        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

        N Offline
        N Offline
        nassimnastaran
        wrote on last edited by
        #3

        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!

        D 1 Reply Last reply
        0
        • N nassimnastaran

          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!

          D Offline
          D Offline
          Dan Mos
          wrote on last edited by
          #4

          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

          N 1 Reply Last reply
          0
          • D Dan Mos

            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

            N Offline
            N Offline
            nassimnastaran
            wrote on last edited by
            #5

            Yes , Thanks , But How can we give an Error and Stop In TabPage1? Regards!

            D 1 Reply Last reply
            0
            • N nassimnastaran

              Yes , Thanks , But How can we give an Error and Stop In TabPage1? Regards!

              D Offline
              D Offline
              Dan Mos
              wrote on last edited by
              #6

              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

              N 1 Reply Last reply
              0
              • D Dan Mos

                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

                N Offline
                N Offline
                nassimnastaran
                wrote on last edited by
                #7

                thanks in Advance !

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups