Disable Sorting in VB.NET

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • simchajoy2000@yahoo.com

    Disable Sorting in VB.NET

    I thought the only thing I had to do to disable column sorting in
    VB.NET was to set datagrid.AllowS orting = False. Unfortunately this
    has never worked for me. I discovered another set of code that seems
    to work for 99% of the cases where I need to disable datagrid column
    sorting:

    Private Sub datagrid_MouseD own(ByVal sender As Object, ByVal e As
    System.Windows. Forms.MouseEven tArgs) Handles datagrid.MouseD own
    Dim pt As New Point(e.X, e.Y)
    Dim hti As DataGrid.HitTes tInfo = dgACE.HitTest(p t)

    If hti.Type <> DataGrid.HitTes tType.ColumnHea der Then
    MyBase.OnMouseD own(e)
    End If
    End Sub

    However, this code does not work when my datagrid resides on a user
    control. The datagrid_MouseD own event is triggered but sorting still
    occurs for the column. It's critical that I disable sorting in the
    datagrid due to the other things I am trying to do with the datagrid.

    I'm about ready to pull my hair out trying to figure this one out so
    any suggestions on how to resolve this issue would be greatly
    appreciated!

    Thank you!

    Joy

  • Scott M.

    #2
    Re: Disable Sorting in VB.NET

    This problem sounds very strange since the DEFAULT of a DataGrid is NO
    SORTING. In other words, you must change a property value AND write code in
    the DataGrid's SortCommand event handler as well as define the sort criteria
    for each column of the DataGrid for sorting to work.

    I find it hard to believe that you get sorting "automatica lly" without doing
    any of these things.


    <simchajoy2000@ yahoo.com> wrote in message
    news:1133978404 .726728.182280@ g47g2000cwa.goo glegroups.com.. .[color=blue]
    >I thought the only thing I had to do to disable column sorting in
    > VB.NET was to set datagrid.AllowS orting = False. Unfortunately this
    > has never worked for me. I discovered another set of code that seems
    > to work for 99% of the cases where I need to disable datagrid column
    > sorting:
    >
    > Private Sub datagrid_MouseD own(ByVal sender As Object, ByVal e As
    > System.Windows. Forms.MouseEven tArgs) Handles datagrid.MouseD own
    > Dim pt As New Point(e.X, e.Y)
    > Dim hti As DataGrid.HitTes tInfo = dgACE.HitTest(p t)
    >
    > If hti.Type <> DataGrid.HitTes tType.ColumnHea der Then
    > MyBase.OnMouseD own(e)
    > End If
    > End Sub
    >
    > However, this code does not work when my datagrid resides on a user
    > control. The datagrid_MouseD own event is triggered but sorting still
    > occurs for the column. It's critical that I disable sorting in the
    > datagrid due to the other things I am trying to do with the datagrid.
    >
    > I'm about ready to pull my hair out trying to figure this one out so
    > any suggestions on how to resolve this issue would be greatly
    > appreciated!
    >
    > Thank you!
    >
    > Joy
    >[/color]


    Comment

    • simchajoy2000@yahoo.com

      #3
      Re: Disable Sorting in VB.NET

      When I talk about sorting, I am referring to the ability to click on a
      datagrid columnheader and sort the specified column by ascending or
      descending order.

      I can tell you that I have no SortCommand event handlers whatsoever and
      perhaps it is strange that it is happening by default but for whatever
      reason that is what is happening. I wouldn't have posted this question
      if I was experiencing what you are suggesting.

      But perhaps I can use the SortCommand event handler to disable this
      functionality.

      Comment

      • Scott M.

        #4
        Re: Disable Sorting in VB.NET

        What EXACT control are you using (Windows or Web Form DataGrid)?
        What Framework/VS.NET are you talking about?

        In VS.NET 2003 (Framework 1.1), there are 3 things that must be done to get
        a Web Form DataGrid to sort (and none of these are done by default):

        The DataGrid must have its EnableSort property turned on (default is off).
        The columns to be sortable, must have a sort field specified (not done by
        default).
        The DataGrid's SortCommand event must contain the code that actaully
        performs the sort (not done by default).

        This is all I can tell you. Good luck.


        <simchajoy2000@ yahoo.com> wrote in message
        news:1133981373 .224288.110020@ o13g2000cwo.goo glegroups.com.. .[color=blue]
        > When I talk about sorting, I am referring to the ability to click on a
        > datagrid columnheader and sort the specified column by ascending or
        > descending order.
        >
        > I can tell you that I have no SortCommand event handlers whatsoever and
        > perhaps it is strange that it is happening by default but for whatever
        > reason that is what is happening. I wouldn't have posted this question
        > if I was experiencing what you are suggesting.
        >
        > But perhaps I can use the SortCommand event handler to disable this
        > functionality.
        >[/color]


        Comment

        • simchajoy2000@yahoo.com

          #5
          Re: Disable Sorting in VB.NET

          I am using the Windows DataGrid with VS.NET 2003.

          1. First, when I type "datagridna me." the intellisense does not display
          the EnableSort property you mention. (fyi. I create a new instance of
          a datagrid by simply dragging and dropping it from the Toolbar onto the
          form.) So I have no idea where this mysterious property you speak of
          resides. There is an AllowSorting property I mentioned previously but
          like I said, it seems to sort no matter if this property is set or not.
          In fact, when I search for "datagrid EnableSort" in the VS.NET help
          topics, it returns 0 topics. Neither can I find anything in
          www.msdn.com on "datagrid EnableSort" - I am still wading through the
          results for "datagrid sort" and haven't found anything yet. So if you
          could refer me to some documentation on "EnableSort " I would greatly
          appreciate it.

          2. Second, I looked and I can find no handler or overridable event
          method called "SortComman d" (or by any other name for that matter) for
          the datagrid.

          3. Third, the previous code I mentioned to disable the sorting
          functionality of a VB.NET datagrid did not come out of my own head. I
          found it in google groups. So if what you are saying is true, why
          wouldn't they have simply set EnableSort = false? Therefore I have a
          feeling that I am not alone when it comes to trying to disable the
          sorting functionality.

          If anyone else has any suggestions or has encountered a similar problem
          I would greatly appreciate any suggested fixes! Thank you.

          Joy

          Comment

          • simchajoy2000@yahoo.com

            #6
            Re: Disable Sorting in VB.NET

            When I did some more searching I was able to find the SortCommand for
            the WebControl datagrid - however, I am working with the Windows Forms
            datagrid and that method does not exist for that control.

            Comment

            • Bart Mermuys

              #7
              Re: Disable Sorting in VB.NET

              Hi,

              <simchajoy2000@ yahoo.com> wrote in message
              news:1133978404 .726728.182280@ g47g2000cwa.goo glegroups.com.. .[color=blue]
              >I thought the only thing I had to do to disable column sorting in
              > VB.NET was to set datagrid.AllowS orting = False. Unfortunately this
              > has never worked for me.[/color]

              What kind of DataSource are you using because i can't reproduce the problem.
              Setting DataGrid.AllowS orting to false does seem to work, but if you use
              DataGridTableSt yle(s) then you must set the relevant
              DataGridTableSt yle.AllowSortin g to false.

              HTH,
              Greetings
              [color=blue]
              >I discovered another set of code that seems
              > to work for 99% of the cases where I need to disable datagrid column
              > sorting:
              >
              > Private Sub datagrid_MouseD own(ByVal sender As Object, ByVal e As
              > System.Windows. Forms.MouseEven tArgs) Handles datagrid.MouseD own
              > Dim pt As New Point(e.X, e.Y)
              > Dim hti As DataGrid.HitTes tInfo = dgACE.HitTest(p t)
              >
              > If hti.Type <> DataGrid.HitTes tType.ColumnHea der Then
              > MyBase.OnMouseD own(e)
              > End If
              > End Sub
              >
              > However, this code does not work when my datagrid resides on a user
              > control. The datagrid_MouseD own event is triggered but sorting still
              > occurs for the column. It's critical that I disable sorting in the
              > datagrid due to the other things I am trying to do with the datagrid.
              >
              > I'm about ready to pull my hair out trying to figure this one out so
              > any suggestions on how to resolve this issue would be greatly
              > appreciated!
              >
              > Thank you!
              >
              > Joy
              >[/color]


              Comment

              • Scott M.

                #8
                Re: Disable Sorting in VB.NET

                Yes, that's why I asked. Sorry, I don't have any info. on the Windows Forms
                DataGrid.


                <simchajoy2000@ yahoo.com> wrote in message
                news:1133991180 .154553.91230@g 49g2000cwa.goog legroups.com...[color=blue]
                > When I did some more searching I was able to find the SortCommand for
                > the WebControl datagrid - however, I am working with the Windows Forms
                > datagrid and that method does not exist for that control.
                >[/color]


                Comment

                • simchajoy2000@yahoo.com

                  #9
                  Re: Disable Sorting in VB.NET

                  Thanks Bart - that did the trick! I was neglecting to set the
                  DataGridTableSt yle.AllowSortin g to False, I was only doing it for the
                  datagrid. Thanks a lot! I'm glad it was such a simple fix!

                  Joy

                  Comment

                  Working...