none
Custom sort on a data-bound Datagridview RRS feed

  • Question

  • Hello, 

    I seem to have a catch 22 on my hands with my DataGridView implementation. I'm loading databound dataset as my datasource. Now so far so good as I was able to use everything at design time to get this going. However my first field is a mixed alpha/numeric field (e.g X-22222). As you can imagine if I sort this field it will sort it alpha. So I went down the rabbit hole of creating my custom sort, however everywhere I go I seem to hit a brick wall when it comes to creating a custom sort for a databound datasource. 

    This is the exception I get Icomparer DataGridView control is data-bound. The control cannot use the comparer to perform the sort operation.

    I've seen online that many people have stopped using data-bound and just manually populated the datagridview, which I could do, but I'm also using a custom DataGridViewAutoFilter, which only works with a databound control (That's where the catch 22 comes in). In case your curious the DataGridViewAutoFilter, basically allows me to have a Excel stype auto filter on the column. If there is an alternative for this somewhere I'll gladly listen. 

    I'm open to any suggestions on how I can get around this. Any information or hints anyone can provide would be greatly appreciated. 

    Thursday, April 14, 2011 8:02 PM

Answers

  • Well I was able to solve my problem as follows. 

     

    My second response actually triggered an idea. What if I just create another field in my view and just hide it. So now I have two fields one that says X-1111 and the other just says 1111. The 1111 field is hidden. I set the property of X-1111 to Sort: Programmatic. Now whenever somebody clicks on that header. I just make a regular sort on my newly created field 1111. Et voila. Not what I really wanted but it works. 

     

    • Marked as answer by Hans Conrad Thursday, April 14, 2011 9:35 PM
    Thursday, April 14, 2011 9:35 PM

All replies

  • On a side note. I did try to sell them the idea of just creating a custom view with this field seperated so it's easily sortable, but it wasn't received well :)
    Thursday, April 14, 2011 8:25 PM
  • Well I was able to solve my problem as follows. 

     

    My second response actually triggered an idea. What if I just create another field in my view and just hide it. So now I have two fields one that says X-1111 and the other just says 1111. The 1111 field is hidden. I set the property of X-1111 to Sort: Programmatic. Now whenever somebody clicks on that header. I just make a regular sort on my newly created field 1111. Et voila. Not what I really wanted but it works. 

     

    • Marked as answer by Hans Conrad Thursday, April 14, 2011 9:35 PM
    Thursday, April 14, 2011 9:35 PM
  • Hi Hans,

    Thank you for sharing your experience here.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 20, 2011 5:26 AM
    Moderator