Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limit Number of Rows In DataGrid?

Status
Not open for further replies.

beefeater267

Programmer
Apr 6, 2005
79
0
0
Hey,

I am using VS.NET 2003 and have a windows application with a datagrid. So, I want the user to be able to enter data in the rows / columns... however, I need to limit them to a max number of 100 rows they can enter. Any way to do this? Any code sample is appreciated!
 
Are you talking about paging...means 100 rows/page or max 100 rows only for that datagrid?

Sharing the best from my side...

--Prashant--
 
Hmm, if you're using a Datatable as the bound datasource, then maybe you can trap on the DataTable.RowChanging event the number of rows already committed. If it exceeds 100, throw an exception. I think the datagrid will display the error message only without breaking the application.

Something like,
Code:
    // Assuming dtsrc is a datatable bound to the grid.
    void dtsrc_RowChanging( object sender, DataRowChangeEventArgs e )
 {
        [COLOR=green]If grid reaches its max and user is on add-row mode...[/color]
        if (dtsrc.Rows <= 100 && e.Action == DataRowAction.Add)
            throw new Exception("Grid is already full.");
    }

Hope this helps [wink]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top