Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Limiting rows in datagridview with BS to dt/ds
Message
From
24/02/2010 17:22:06
 
 
To
24/02/2010 09:53:05
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
VB 9.0
Miscellaneous
Thread ID:
01450646
Message ID:
01450852
Views:
43
Thanks Bonnie -

Here's what I have so far :
Imports System.Windows.Forms

Public Class dgv
    Inherits System.Windows.Forms.DataGridView

    Private _Rowlimit As Int32
    Public Property Rowlimit() As Int32
        Get
            Return _Rowlimit
        End Get
        Set(ByVal value As Int32)
            _Rowlimit = value
        End Set
    End Property



    Private Sub dgv_RowLeave(ByVal sender As Object, ByVal e As _
          System.Windows.Forms.DataGridViewCellEventArgs) Handles Me.RowLeave

        If Me.Rowlimit > 0 And Me.RowCount > Me.Rowlimit Then

            MessageBox.Show("Maximun records (" & Me.Rowlimit & ") reached.")

            Me.AllowUserToAddRows = False

        Else
            Me.AllowUserToAddRows = True
        End If

    End Sub

    Private Sub dgvContainer_RowsRemoved(ByVal sender As Object, ByVal e As _
       System.Windows.Forms.DataGridViewRowsRemovedEventArgs) Handles _
       Me.RowsRemoved

        If Me.Rowlimit = 0 Or Me.RowCount < Me.Rowlimit Then

            Me.AllowUserToAddRows = True

        End If

    End Sub

End Class
Works okay except the messagebox fires once when you try to add max+1 and once again when you leave the grid. I think I can come up with a non-modal notification ( Strataframe has a lot of toys ) that might solve that awkwardness. I will probably be buying the Infragistics stuff soon so this whole thing may become moot. The dgv is pretty primative in a lot of way. (and soon I'll probably be doing all my UI in WPF so who knows what is in store for me there <bg>


>Hi Charles,
>
>I can't seem to find a property of the datagridview so i was thinking I need to subclass the dgv, add a max rows property and handle whatever event raises when the user attempts to add another row to either permit it or show a messagebox explaining the limit.
>
>That would work fine, IAC you should *always* use a grid sub-class anyway, never use the .NET classes directly.
>
>Another option is to totally turn off allowing users to add a row via the Grid (set the AllowUserToAddRows property to false) and have an Add button on the form. Disable the button when the max number of rows have been added.
>
>~~Bonnie
>
>
>
>
>>I have datagridviews using bindingsource bound to dataset with member being datatable.
>>
>>These are being used to fill out PDF forms so I would like to be able to limit the number of rows that can be entered in some of the grid so the user does not enter more rows than the PDF form can handle.
>>
>>Is there a clean, generic way someone has come up with to do this? I can't seem to find a property of the datagridview so i was thinking I need to subclass the dgv, add a max rows property and handle whatever event raises when the user attempts to add another row to either permit it or show a messagebox explaining the limit.
>>
>>Thoughts? ( vb or c# )
>>
>>TIA


Charles Hankey

Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy

Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.

-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin

Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.
Previous
Reply
Map
View

Click here to load this message in the networking platform