Datagrid Rows

How to set the Max row count

Page 1 of 1

5 Replies - 6571 Views - Last Post: 22 April 2008 - 10:56 AM Rate Topic: -----

#1 zakary  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 427
  • Joined: 15-February 05

Datagrid Rows

Posted 22 April 2008 - 08:11 AM

I am using a Datagrid to add some configuration fields I only want to user to enter a total of 5 rows no more, I have google'd and have not found any info on setting the Max number of rows. Is this possible.

This post has been edited by zakary: 22 April 2008 - 08:12 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Datagrid Rows

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Datagrid Rows

Posted 22 April 2008 - 08:16 AM

5 rows per page or you just want to limit the results to 5 rows total?
Was This Post Helpful? 0
  • +
  • -

#3 zakary  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 427
  • Joined: 15-February 05

Re: Datagrid Rows

Posted 22 April 2008 - 08:28 AM

5 rows total the user can add and delete rows but when they can never have any more than 5 rows in the datagrid
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Datagrid Rows

Posted 22 April 2008 - 09:31 AM

There isn't a max count property that I know of. You will just have to check the row count each time a user adds a new row and disallow if there is 5 rows already.

Are you using a DataSource to bind to your DataGrid, like a DataSet?

You will need to get the row count from the data source, not the DataGrid.
Was This Post Helpful? 0
  • +
  • -

#5 zakary  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 427
  • Joined: 15-February 05

Re: Datagrid Rows

Posted 22 April 2008 - 10:00 AM

Thanks Jayman I figured it out I had to add in my InitializeComponent() method a RowEnter event handle on my dataGridView

dataGridView1.RowEnter += new System.Windows.Forms.DataGridViewCellEventHandler(dataGridView1_RowEnter);


then I add the following code and it works the user can only add 5 rows
void dataGridView1_RowEnter(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
        {
            if (dataGridView1.RowCount >= 6)
            {
                dataGridView1.AllowUserToAddRows = false;
            }
        }


This post has been edited by zakary: 22 April 2008 - 10:01 AM

Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Datagrid Rows

Posted 22 April 2008 - 10:56 AM

Originally you said you were working with a DataGrid, but I see you are actually using the GridView.

Just an FYI, it is important to state the correct controls that you are using. We will then be able to provide more effective and accurate answers.

I am glad you were able to arrive at a solution.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1