Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,070 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,588 people online right now. Registration is fast and FREE... Join Now!




Datagrid Rows

 
Reply to this topicStart new topic

Datagrid Rows, How to set the Max row count

zakary
22 Apr, 2008 - 07:11 AM
Post #1

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 404



Thanked: 6 times
Dream Kudos: 175
My Contributions
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 Apr, 2008 - 07:12 AM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Datagrid Rows
22 Apr, 2008 - 07:16 AM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,919



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
5 rows per page or you just want to limit the results to 5 rows total?
User is online!Profile CardPM
+Quote Post

zakary
RE: Datagrid Rows
22 Apr, 2008 - 07:28 AM
Post #3

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 404



Thanked: 6 times
Dream Kudos: 175
My Contributions
5 rows total the user can add and delete rows but when they can never have any more than 5 rows in the datagrid
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Datagrid Rows
22 Apr, 2008 - 08:31 AM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,919



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
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.
User is online!Profile CardPM
+Quote Post

zakary
RE: Datagrid Rows
22 Apr, 2008 - 09:00 AM
Post #5

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 404



Thanked: 6 times
Dream Kudos: 175
My Contributions
Thanks Jayman I figured it out I had to add in my InitializeComponent() method a RowEnter event handle on my dataGridView
csharp


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
csharp

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 Apr, 2008 - 09:01 AM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Datagrid Rows
22 Apr, 2008 - 09:56 AM
Post #6

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,919



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
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.
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 07:04PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month