Saturday, May 3, 2014

A .NET WinForm DataGridView with advanced capabilities

This components is a .NET WinForm DataGridView with advanced capabilities, it is an extention of the .NET WinForm DataGridView.


The project is a refactoring of "Advanced DataGridView with Excel-like auto filter" you can find here: https://adgv.codeplex.com.
The author, also post this as a patch in the project page.

This Enhanced DataGridView components features:
  • Ascending or Descending Sort order for any column, by code or run-time
  • Filter any column using a Custom Filter, or selecting values from using an Excel-like Filter List view, using also an advanced feature for DateTime types
  • Saving and Restoring preset for Filter and Sort
  • Enabling or Disabling Filter and/or Sort features for any column,by code or run-time
  • Search ToolBar to find values in columns
A Sample project is attached in code to test this DataGridView.

It is written using Microsoft Visual Studio 2012, using the .NET 4.0 framework.

Copyright (c), 2014 Davide Gironi <davide.gironi@gmail.com>
Original work Copyright (c), 2013 Zuby <zuby@me.com>
This project is licensed under the Microsoft Public License (Ms-PL), see attached LICENSE file for further information.


ChangeLog

  • 1.0.x.11: fixed DateTime filter problem
  • 1.0.x.10: fixed AdvancedDataGridViewSearchToolBar problem with not Visible column search
  • 1.0.x.9: first release


Code

Notes
  • read risk disclaimer
  • excuse my bad english

175 comments:

  1. Hello
    Displaying the project I would like to know if there in VB. I have translated with code translators (Instant for VB from Tangible Solutions) but does not work in especially in the case of filter dates.
    I think the problem is in the translation BuildNodes(ByVal vals As IEnumerable(Of DataGridViewCell)) for data type for dates

    Sorry for my bad English
    Regards from Spain and thanks
    Eduardo my mail is e.gomez.lopez@hotmail.com

    ReplyDelete
    Replies
    1. This project is written in C#, no VB, but you could use it in any VB.NET WinForm project, adding the compiled dll as a reference. I've never try auto-transaltor. You should modify the c# code, instead of translatin it.

      Delete
  2. Hello,
    I have a problem. When I filter a column checking "Blanks" value, then I try to reset Filter, but all the data get lost and therse no way to getting back even if i try to repopulate databinding.

    ReplyDelete
    Replies
    1. Hello,
      unluckly i don't get this issue. Try to tell me step by step how do you get this error. Let's take AdvancedDataGridViewSample as example, if I open this sample program, the i click on the "string" column filter/order icon, then i select only the "(Blanks)" value. I get the blank filtered. Then if i check "(Select All)" or i click "Clean Filter And Sort" button, the filter resets, and the column are all repopulate.

      Delete
    2. Ho, have you solve this problem??

      Delete
  3. Thanks for answer Davide. Im gonna try with example and see wath happens. comming back with coments!

    ReplyDelete
  4. How can I implement this in a vb project on an already created and bound DataGridView? I can't get it to work. An example of the code would be nice. Thanks

    ReplyDelete
    Replies
    1. Hello, there are at least two ways. One is to remove your old datagridview components form you form, and then add this new grid you have added to your toolbox. Another is just to rewrite the code of the designer to initialize the AdvancedDataGridView. Before starting up to replace the DataGridView of you project, my suggestion is to recreate the sample project "AdvancedDataGridViewSample" in VB, the porting will be easy.

      Delete
  5. David, this is the best example of what Microsoft SHOULD do, but do not. However, like Colton, I need a better understanding of how to implement this into a project using VB. I have import the dll but no extra datagridview appears in my toolbox.

    Can you please provide some support code to use your product?

    ReplyDelete
    Replies
    1. Thank you. Before using this components. You should add this item to the toolbox. Right-click on toolbox - Select "Choose Items" - Browse to your DLL - Add the item.
      Then use this as a normal grid, You just have to attach two handler in order to make it works, the FilterStringChanged and the SortStringChanged, set the BindingSource Sort and Filter property here, take a look at the Sample project. Then there are other thing you can do with this grid, but that's the basic.

      Delete
    2. hi Davide very good job
      in the filteringstringchanged he didnt recognise the zuby from the zuby.adgv.advanceddatagridview
      thanks

      Delete
    3. Hello, tahnk you for this feedback. Please be more specific, I can not understaind where's the missing attach point here.

      Delete
    4. thanks davide for the reply
      i put reference to your dll file and it worked
      thanks a lot and again good job

      Delete
    5. Happy to hear that. Thank you and good work.

      Delete
  6. Davide,
    I've downloaded the source code and tried to load your solution for some testing. Unfortunately, the source doe zip file you provided seems to have a problem. When I load it in VS 2012 or 2013 the code runs fine but trying to open the AdvancedDataGridViewSearchToolBar and AdvancedDataGridView components just come up blank on the design surface. What am I missing?

    Thanks,
    Stephen

    ReplyDelete
    Replies
    1. Hello, I've imported it to VS2013, and rebuild the project. No problem at all here. It happens even if you drag and drop a new AdvancedDataGridView from the toolbox to the FormMain of the sample project?

      Delete
  7. No, I can use the ADGV control with out problems but what doesn't seem to be working for me is opening the Advanced DataGridView CS project and trying to view the AdvancedDataGridView.cs control on the designer surface.

    ReplyDelete
    Replies
    1. The AdvancedDataGridView class in an extention to the DataGridView, then, it will not be painted by the visual studio designer as an editable component. Sorry about that.

      Delete
  8. @Davide Thanks for example actually i am working on similar approach i am pass the the data table for grid view



    DataTable dataobj = new DataTable();

    dataobj.Load(rdr); // some query and it have some data in it

    advancedDataGridView_main.DataSource = dataobj; // pass to your grid view component my data table


    and filter function of excel ( kind of throwing some exception )

    can you help me out


    my showing some example

    passing the datatable for gridview ?

    ReplyDelete
    Replies
    1. Hello and thank you for your feedback. If you look at the FormMain constructor in the FormMain class of the AdvancedDataGridViewSample
      project, you could see how i load the AdvancedDataGridView DataSource.

      Delete
  9. Davide, I really need some help. I am populating the ADGV with database query. No can you give the population of ADGV with some database example.
    After I load the ADGV with SQL Query, the ADGV load the data properly and shows the filters as well. But I am not able to populate the datasource back while filtering. Can you explain completely with one example.

    My Source code is like below

    public void loadGrid()
    {

    sql = "Select * from tbl_IdDetails";
    sql1 = @" SELECT [Branch Code]
    ,[Server]
    ,[UserID]
    ,[NAME]
    ,[NNFCTCL]
    ,[NNF CASH]
    ,[FOCTCL] from tbl_IdDetails";

    objFunc.populateGrid(sql1,ADVANCEDDATGRID);



    }


    private void multiEditDataGridViewPanel1_FilterStringChanged(object sender, EventArgs e)
    {

    bindingSource_main.Filter = ADVANCEDDATGRID.FilterString;
    }

    I am not able to pass the data source back while filtering. Please help with an complete example. Thanks for your help.

    ReplyDelete
    Replies
    1. You can set you datagrid DataSource to your BindingSource, then you could load you BindingSource.DataSource with a DataTable loaded with the database rows.

      Delete
    2. Davide, Thanks for your reply. I tried but not able to figure it out. I am very new to dot net and Not able to manipulate much. Can you please give a complete example with full code??? A complete code with database connectivity?

      Thanks very much for your help in advance.

      Delete
    3. I'm sorry but I usually does not provide complete examples on request, because if I do this for you, I have to do this for any asking this, and I have not time to do this for any request. Really sorry.
      I can just poin you to the solution. First step: have you done this with a standard DataGridView?

      Delete
    4. Yes, I did this with a standard DataGridView. After that the filter is applied on them. The data with filter is coming properly. But when I use the filter, datagrid does not refresh with the filter.

      Please let me know how to set the filter with filter string. just that line of code.

      Delete
    5. Ok, let's do it at steps. Use an AdvancedDataGridView, with the attached FilterStringChanged method. Add a debug point on you set filter function (i mean here in your example above: bindingSource_main.Filter = ADVANCEDDATGRID.FilterString;) the when you trigger a filter event (as exemple by setting a custom filter), take a look to the "FilterString". Does it contains the proper filter string for the BindingSource?

      Delete
    6. Using the AdvanceDataGridView Control. This is the below complete control on load of the page and then on filter string. It is giving error that filter string is null

      public IdDetails()
      {
      InitializeComponent();
      _dataTable = new DataTable();
      _dataSet = new DataSet();

      //initialize bindingsource
      bindingSource_main.DataSource = _dataSet;

      //initialize datagridview
      multiEditDataGridViewPanel1.DataSource = bindingSource_main;

      //set bindingsource


      }



      public void loadGrid()
      {

      sql = "Select * from tbl_IdDetails";
      sql1 = @" SELECT [Branch Code]
      ,[Server]
      ,[UserID]
      ,[NAME]
      ,[NNFCTCL]
      ,[NNF CASH]
      ,[FOCTCL] from tbl_IdDetails";
      objFunc.populateGrid(sql, multiEditDataGridViewPanel2);
      objFunc.populateGrid(sql1, multiEditDataGridViewPanel1);
      objFunc.DatatableData(sql1, _dataTable);

      multiEditDataGridViewPanel2.Columns[3].Frozen = true;


      }






      private void multiEditDataGridViewPanel1_FilterStringChanged(object sender, EventArgs e)
      {

      bindingSource_main.Filter = multiEditDataGridViewPanel1.FilterString;
      }

      private void IdDetails_Load(object sender, EventArgs e)
      {
      loadGrid();
      objFunc.InitializeEditableDataGridView(multiEditDataGridViewPanel2);


      }

      Delete
    7. Hello, please do not flow with comments of code here. Instead build a little project sample. Do not load data with a dabatase but just create sample data. Then, when you've got this, share the solution link one can download to test. From what i see it could be the populateGrid function. If the FilterString is null, something goes wrong in the filter creation procedure. You can see it debugging the code from the advanceddatagrid.

      Delete
  10. Hello, how can I make this sln file work with my VS 2008? It is a requirement of me to use VS 2008 at the moment, so can't change to newer editions.

    ReplyDelete
    Replies
    1. You can create a new solution, new project and import files. Or you can try to edit by hand the csproj/vbproj files setting "Microsoft Visual Studio Solution File, Format Version" to 10.00 (which is Visual Studio 2008), but I'm not shure it will works.

      Delete
    2. This comment has been removed by the author.

      Delete
    3. Thank you for the input. It already is set to 10.00, unfortunately. If theoretically I build this from a newer edition of VS 2008 and get the dll and include it to my references, how would I use it in my project? Is it a completely new control type which I must substitute in place of the normal datagridview?

      Delete
    4. It's an extention of the DataGridView, you can build with other VisualStudio as long as you are using .NET 4.

      Delete
  11. I'm trying to use it, but I can't see how to set BindinSource DataSource with dataSet, like the sample. There's no step by step to use this component, so it's not very helpful. :(

    Also, if I don't populate the grid with DataTable (I'm currently using AddRows), is it possible to still make ADGV work?

    Thanks!

    ReplyDelete
    Replies
    1. Hello, you just have to use attach the Bindisource like you usually do on DataGridView. Looking at the sample provided, the line "advancedDataGridView_main.DataSource = bindingSource_main;".

      Delete
    2. Right. I've got it. The only problem now is that I don't know how to pass a list of DataGridViewRow to the BindingSource DataSource, because by doing this I see all DataGridViewRow class members instead of Cells content only. This code doesn't seem to work:

      bindingSource.DataSource = dgvRowsList;
      bindingSource.DataMember = "Cells";
      datagrid.DataSource = bindingSource;

      Any idea?

      Thanks once again :)

      Delete
    3. You could load a typed IEnumerable (let's say for example you have a class Person, you will load a IEnumerable enumberablePerson = ...), then convert it to a DataTable and load it as your BindingSource.DataSource by using something like this: yourBindingSource.DataSource = DGDataTableUtils.ToDataTable(enumberablePerson);
      You can find the ToDataTable here: https://gist.github.com/davidegironi/9348c74c01d979942901#file-dgdatatableutils-cs
      Also remember to set the DateGridView.DataSource to the BindingSource, like you are doing: yourDataGridView.DataSource = yourBindingSource

      Delete
    4. Hmmm... For architecture reasons I'm trying to avoid DataTables. :(

      Delete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Hi David - new to your site - have downloaded the dll and added to both references and to the toolbox in VS2013. Bound datasources for 2 applications - one VB net and the other is in C# -- both access and load the data, but alas the autofiltering function and sorting both don't respond. The complete dataset remains displayed as initially loaded. Any ideas? =Vytas A

    ReplyDelete
    Replies
    1. Hello. Have you FilterStringChanged and SortStringChanged EventHandler to you AdvancedDataGridView instance? Take a look to the FormMain from the provided sample as reference.

      Delete
  14. I am unable to add the DLL in tool box in VS2015. Please let me know if I need to do anything specific to make it compatible with VS2015

    ReplyDelete
    Replies
    1. Hello, Does the sample project provided with code get imported and runned?

      Delete
  15. This comment has been removed by the author.

    ReplyDelete
  16. your project is really good, thank u, one problem that i have is, i want to enable only one column sort like excel. if i sort a second column the old sort filter in the other column should be cleared like that of excel. is there any way to do this?? Thank you..

    ReplyDelete
    Replies
    1. You have to modifiy the code. You could change the MenuStrip.SortChanged event in order to CleanSort just for the not selected columns.

      Delete
  17. hi,thank u for replying,i added an else{cleansort} for cell_sortchanged its giving the desired result,but the ascending and descending image don't change..any ideas

    ReplyDelete
    Replies
    1. Images changes on sortASCMenuItem_Click and sortDESCMenuItem_Click methods, add a debug point there, see what's happenen...

      Delete
    2. ok, i will,is there anyway to disable custom sort and enable the default datagridview sort??
      Thank You

      Delete
    3. Not by default. MenuStrip is the key again for this.

      Delete
  18. Hi Davide,

    During a small project I am working on I found your remake of the ADGV Dataview.
    I am having a small issue and was hoping you can help me a bit.

    I’ve setup a DataBinding to an SQL server and the information is showing correct. However the filter and sort isn’t working.
    I found you posted this on your blog:

    just have to attach two handler in order to make it works, the FilterStringChanged and the SortStringChanged, set the BindingSource Sort and Filter property here, take a look at the Sample project. Then there are other thing you can do with this grid, but that's the basic.

    I can’t open the Sample project in 2015 and I am pretty new to programming so I was hoping you can help me a bit. Can you explain a bit what I need to do to get it working?

    Thank you!
    Mike

    ReplyDelete
    Replies
    1. Hello,
      This sample project was built in VS2012.
      VS2015 should be able to import the VS2012 project. I'm using VS2013 and VS2015 for other projects, and never encounter problems on opening VS2012 solutions with VS2013 or VS2015.
      What's the problem VS give you on opening the VS2012 solution?
      Anyway that's right, you just have to attach the Filter and Sort events.

      Delete
  19. Hello Davide. Good stuff here :)

    However the current date filtering wasn't working for me with a en-US culture.

    Long story short, here's a fix that should work across all cultures when it comes to the date formatting used in the controls current date filtering.

    The 2 files to modify are FormCustomFilter.cs and MenuStrip.cs.

    In MenuStrip on line 67-68 change const to readonly;

    private const string ConvertYearMonthDayFormat = "dd/MM/yyyy";
    private const string ConvertYearMonthDayHourMinuteSecondFormat = "dd/MM/yyyy HH:mm:ss";

    to

    private readonly string ConvertYearMonthDayFormat = dd/MM/yyyy";
    private readonly string onvertYearMonthDayHourMinuteSecondFormat = "dd/MM/yyyy HH:mm:ss";

    Then go to line 88 in the constructor and insert the following;

    ConvertYearMonthDayFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
    ConvertYearMonthDayHourMinuteSecondFormat = ConvertYearMonthDayFormat + " " + CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern;


    Just do the same thing to FormCustomFilter.cs.

    There may be a reason not to use these changes, but it's working for me in both my test cases.


    But anyways, good stuff :)

    ReplyDelete
    Replies
    1. Hello and thank you for your feedback!
      Can you try this version? http://wikisend.com/download/436394/AdvancedDataGridView-src_1.0.19617.11.zip
      I think I've fixed it for multi-cultures. I've checked it overriding the program culture by the code you find in sample Program.cs and it seems to me to work. Before posting it i just need your checking feedback. Thank you.

      Delete
    2. Ok, I have it. I'll be able to check it in a couple hours.

      Delete
    3. Ok, that seems to have fixed it Davide. Good job.
      Yup, I'd release that version. It's pretty important :)

      On a side note. I have a bug fix/check (dealing with Image columns) and a new feature (dealing with the filtering) that I'm working on. I was thinking of publishing your source to BitBucket. If you don't have any objections that is. I can make you lead on it of course lol. This way others can issue Pull requests when they make good changes to thier own version.

      Up to you man. I'm gonna publish it anyways because I like source control hehe. But, I'll make it a private repo without your blessing.

      Delete
    4. Hello, thank you for your feedback. Yes, it's time to move this project to a CVS. I'm using bitbucket for my private repository, and GitHub for public. You can find the code on the GitHub link above. Hope it's not a problem for you GitHub instead of BitBucket.

      Delete
    5. Absolutely not man. I use GitHub too :)
      Cool.

      Delete
    6. David, could You upload egain your fixed Advenced DGV? I will be very greatfull for that :)

      Delete
    7. Hello, you can find the last version of this project (the fixed 1.0.*.11 one) in the gitub page, there you can also find the compiled release. I've to take time to test and merge the Earl pull, I hope to have time next week.

      Delete
    8. Great job man, very very helpfull!

      Delete
    9. Unfotunetly Your ADGV doesn't support a column type of 'Time'. I work on hh:mm:ss format and this is the same problem like before with dates. David, could You help me with that or give me some advice how to manage this problem?

      Delete
    10. Hi David,

      Thanks for providing this useful stuff.

      I have one problem with date time calendar control with Advance datagridview.

      After binding it make that calendar control column readonly(not editable).

      Can you please help in that?

      Delete
    11. Hello Bartosz, please check the new release, it should even work with TimeSpan.

      Delete
    12. Hello Brinda, I've checked it, but to me it seems to works. Can you packup a sample?

      Delete
  20. Hi there David, I was searching for something exactly like this for a project of mine and this seems like this will do the trick.
    I have a question for you though, the data gridview, lets say I added some data into the table which is displayed in the gridview from another form and when I open the form where the filter functionality is located, will the gridview show the updated/newly added values or not?

    I am asking this because currently i am not able to access my pc
    that is used for development.

    ReplyDelete
    Replies
    1. Hello, the databinding of this component works exactly like the Microsoft winform datagridview, so if you set the Datasource of this grid to a BindingSource DataSource, if you take a look to the sample provided code, you will notice that the DataSource of this component it is set to a BindingSource before the binding source is loaded, then when it is loaded by the SetTestData method, the table is populated.

      Delete
    2. Ok so I found out that the data/table is generated from here I guess.

      //initialize bindingsource
      bindingSource_main.DataSource = _dataSet;

      //initialize datagridview
      advancedDataGridView_main.DataSource = bindingSource_main;

      //set bindingsource
      SetTestData();

      so what should I add here if I want to add my own data table instead of the one used in the sample

      Delete
    3. You just have to set DataSource to your _dataSet, then load this with SetTestData

      Delete
  21. Could you tell me what changes I need to main in the FormMain so that My table is displayed rather than the one that is already being used

    ReplyDelete
    Replies
    1. Hello. To load the Main table would not be so difficult, but i think you have to understand why does it works that way. The best thing you can do is to follow some tutorial on .NET bindingsource tutorial.

      Delete
  22. Hi David,

    Thanks for providing this useful stuff.

    I have one problem with date time calendar control with Advance datagridview.

    After binding it make that calendar control column readonly(not editable).

    Can you please help in that?

    ReplyDelete
    Replies
    1. Hello, do you mean that all the cells of a datetime column are readonly, and column of other type, like string, has cells that be edited?

      Delete
    2. Yes actually I am using calendar control data grid view column in it.
      But figure out the solution I have to manually set that column property read only true and than its working fine.

      Want to take your guidance on another thing as well. If I use this grid for 8-10 columns its loading is pretty much fast 1-5 sec but when working with 100 columns its taking 40 secs which is bit more.

      Can you focus on that part of optimization?

      Delete
    3. For that amount of column you can disable the sorting andor filtering for all the column that you do not use. Or, if you want, you can try the optimization on the code on github, then do a push.

      Delete
  23. Is there an option of numeric sort? TIA.

    ReplyDelete
    Replies
    1. Hello, yes, it's the sort icon on each column header. So if the underline column has a numeric datatype it will be sorted by numeric order.

      Delete
  24. Hi Davide Gironi,

    I am using your datagridview and it is fantastic!!! I get data from database and bind to your advancedgridview and the filters are brilliant.

    There is a functionality in the app to get the latest data on pressing F5. When i remove the datasource and rebind with the new data, the filters are lost.

    Is there a way to retain the filters with refreshing of data. Please let me know asap. Thanks in advance.

    ReplyDelete
    Replies
    1. Hello, thank you for your feedback. Filter and sorting does not change even if you reload the attached BindingSource. And there's a save and restore filter and sort function.

      Delete
    2. Thanks for your response. Can u pls send me a sample code for that? Thanks.

      Delete
    3. This comment has been removed by the author.

      Delete
    4. This is how it works to me, without any change.

      Delete
    5. I did change the code as below:
      bdSharepointSource.DataSource = dtSharepoint
      bdSharepointSource.ResetBindings(False)

      I am updating datatable dtSharepoint and reassigning to binding source and calling resetbindings.

      It is working as expected. I could see the changes coming in. But when i click on clear filter of any one column, all filters are getting cleared. Can you please check whether this issue is there in your code and let me know? Thanks again for your help.

      Delete
    6. Staring from the project sample. Add a Reload button that perform
      _dataTable.Rows.Clear();
      AddTestData();
      In the sample, that way filters and sort does not change.

      Delete
    7. It worked. Thanks a lot for your help and timely help.

      Delete
  25. This comment has been removed by the author.

    ReplyDelete
  26. This comment has been removed by the author.

    ReplyDelete
  27. For an instance, I opened the filter menustrip by clicking the filter button. The filter menu is now open. If I want to close the filter menu, either I have to click on 'Cancel' button or I have to click somewhere else on the datagridview. But we I re-click on the same filter button (of the column which already menustrip is open), the filter menustrip closes and opens again. On this second click, it should only close and should not open again.

    ReplyDelete
    Replies
    1. Hello, and thank you for suggestion. I've reply you on GitHub.

      Delete
  28. Where to download more components like this ADGV? I would like to download an advanced listbox, which accepts multiple columns with multiple fields

    ReplyDelete
    Replies
    1. Hello, the only other "enhanced" components I've publish can be found here http://davidegironi.blogspot.it/2016/02/enhancedboxhelper-net-winform-component.html it is a TextBox, a ComboBox and a DateTimePicker. Hope this helps.

      Delete
  29. Hi Davide,

    Great component. Awesome Work. Seems my filter is hanging when I change data source. How to I call the clear filter?

    ReplyDelete
    Replies
    1. Never mind I found it. Silly me. Thanks
      bindingSource1.RemoveFilter();

      Delete
    2. Hello, thank you. Also thank you for posting your solution here.

      Delete
  30. private void fee_create1_Load(object sender, EventArgs e)
    {
    //return to datatabl
    this.advancedDataGridView1.DataSource = pardeep.Show_Data("SELECT * from student");
    }

    private void advancedDataGridView1_SortStringChanged(object sender, EventArgs e)
    {

    //what code type here to sort advancedDataGridView column
    }
    private void advancedDataGridView1_FilterStringChanged(object sender, EventArgs e)
    {
    //what code type here to filter advancedDataGridView column
    }

    ReplyDelete
    Replies
    1. Hello, it depends on what your "Show_Data" method returns. The best things is to attache de DataSource of a BindingSource to a dataset, the the DataSource of the datagridview to the BindingSource generated. You can take a look at the sample file provided in source code, it may help.

      Delete
    2. If we Use sql query to store data in ADGV then what
      How to sort

      Delete
    3. Hello, you should link your store to a bindingsource. You could find an example at the dentnet project here: https://github.com/davidegironi/dentned

      Delete
  31. Is it possible grouping rows ?

    ReplyDelete
  32. Hi Davide,

    Quick question relating to loading saved filters.

    After loading a saved filter the filter options are locked so the user would not be able to 'extend' the saved filter with additional filter options [post load].

    Is there any way, after loading a filter to enable the filter options to remain available to the user for them to further filter the results?

    Thanks.

    ReplyDelete
    Replies
    1. Hello, not using the provided code, a few coding is needed to implement this behaviour. Hope this helps.

      Delete
  33. Thanks for the super speedy response!

    ReplyDelete
  34. This comment has been removed by the author.

    ReplyDelete
  35. Hello Davide:

    When I was using your filters I would like to know how to update the filter options when the following case happens:

    In a status column I have only "new" items. So, it is unable to have different filters options. Once that I update a row with "solved", how could the filter option "load" the new item "solved" automatically? In order to have "new" and "solved" filter options.

    ReplyDelete
    Replies
    1. I already try:

      dataGridView1.LoadFilterAndSort(dataGridView1.FilterString, dataGridView1.SortString);

      But, filters, sorts and Icons became gray and disable (gray).

      Delete
    2. Hello, the LoadFilterAndSort behavior is to disable the filter icon, in order to preload the filters you have to implement your how function or change the code behind the LoadFilterAndSort method. If you do this please share it, it will be usefull it could be something parametric like LoadFilterAndSort(... , bool disableAfterSet).

      Delete
  36. Hi, greate control how do you implement double buffering, I am using the Dll in a VB project

    ReplyDelete
    Replies
    1. Hello and thank you, no the double buffering is not implemented yet, but thank you for suggestion, if you are going to implement that please let me know.

      Delete
  37. Hi,

    the only way I have been able to implement double buffering is by following method

    Public Sub MakeAdvancedGridViewDoubleBuffered(ByVal dgv As Zuby.ADGV.AdvancedDataGridView)
    Dim dgvType As Type = dgv.[GetType]()
    Dim pi As PropertyInfo = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance Or BindingFlags.NonPublic)
    pi.SetValue(dgv, True, Nothing)
    End Sub

    Aslo with the searchtoolbar, is is possible that when it finds the data, it brings that row into focus on the grid, reason I ask, is my grid has 10,000 items, the search does find and highlight but would be better if moves grid to found item.

    ReplyDelete
    Replies
    1. Thank you for your suggestion, I will add a public SetDoubleBuffered() method on the AdvancedDataGridView in the next release. About the list, set _checkTextFilterRemoveNodesOnSearch to true in the MenuStrip class, is that the behaviour you are searching for?

      Delete
    2. Yes that is exactly what I wanted, maybe in next release you could make a setting to enable/disable this feature

      Delete
    3. Hello, take a look at this version, let me know it everything works like expected: https://expirebox.com/download/0cf9b6140dfc2a01656d9818bedd7903.html SetDoubleBuffered, SetTextFilterRemoveNodesOnSearch and GetTextFilterRemoveNodesOnSearch are added

      Delete
    4. Yes that seems to be fine, great work

      Delete
  38. Hi,
    BTW I am a novide VB coder
    I have another question around the search bar

    I have the following code:

    'initialize dataset
    dt = New DataTable

    Cursor = Cursors.WaitCursor 'and some various me.Cursor / current.cursor
    Application.DoEvents()

    Try
    Dim ds As New DataSet
    Using cnn As New SqlConnection(ConnStr)
    cnn.Open()
    Using dad As New SqlDataAdapter(strSql, cnn)
    dad.SelectCommand.CommandTimeout = 120
    dad.Fill(ds, "data")
    End Using
    cnn.Close()
    End Using

    If ds.Tables(0).Rows.Count < 1 Then Exit Sub

    ' Set dataset to datatable
    dt = ds.Tables(0)

    ' initialize bindingsource
    BindingSource_Main.DataSource = dt

    'initialize datagridview
    DataGridView1.SetDoubleBuffered()
    DataGridView1.DataSource = BindingSource_Main

    'set bindingsource
    BindingSource_Main.DataMember = dt.TableName
    advancedDataGridViewSearchToolBar_main.SetColumns(DataGridView1.Columns)

    When I use the last 2 lines I get datamember'datamember property data cannot be found on datasource

    Also my grid has a lot of hidden columns, how do I bind the search to only visible columns.

    All help is appreciated.

    ReplyDelete
    Replies
    1. Hello Paul, for long code sample request, please use pastebin. Anyway, now I can not test this, but I think you can build a new column collection without the coulum you do not need, or just override the attached Search method to skip unwanted columns.

      Delete
  39. Hi,

    Me again, I resolved my searches by skipping, I have another question.

    I have a hidden column with is true or false, this is represented by an image in a visible column.

    How do I set this hidden column to be filtered on a specific value in code, that way I can have a button to enable/disable etc, or if have other columns similar but I want to say filter column a by multiple options.

    Thanks

    ReplyDelete
    Replies
    1. Hello, like you said below, you can use the Filter on Binding Source, there is no way to pragmatically set a column except the LoadFilterAndSort method, but that disable any filters. This could be a nice feature for the future.

      Delete
  40. Hi

    Think I have resolved I have just used .filter on the Binding Source

    ReplyDelete
  41. Hi, Do you know why if i use DataboundItem, it always null?

    ReplyDelete
    Replies
    1. Hello. What are you using DataboundItem for?

      Delete
    2. I want to Move another Form with data in the ADGV. and using advancedDataGridView1.CurrentRow.DataBoundItem as CustomObject. but it said Null, when I Check it has the data, But I can't cast it to the object.. do u have a way to casting this?

      Delete
    3. I think you have to custom code the AdvancedDataGridView for that. Sorry about that.

      Delete
  42. Hi,
    very nice tool!
    Im seaching for the latest BINARY version of AdvancedDataGridView.dll (version 0.1.0.11)
    I had a look at https://github.com/davidegironi/advanceddatagridview
    but wasn't able to find it.
    Could you please give me advice?

    Thanks in advance
    Bernd

    ReplyDelete
    Replies
    1. Hello, you can go to the github link and then click to "Latest Release" link in the description, this is the link of the actual version: https://github.com/davidegironi/advanceddatagridview/releases/tag/1.0.x.19

      Delete
    2. PERFEKT - many thanks for this and a happy new year

      Delete
  43. Hi Davide,

    Thanks for the cool tool. I've been using this in a few projects and am able to make all the features work thanks to the sample project in the hub. I was wondering whether you're aware if anybody got this to work with binding lists or something like that instead of Datatables which forces me to add another step to convert my lists to datatables using libraries like FastMember, etc..

    Thanks

    ReplyDelete
    Replies
    1. Hello and thank you for your feedback! I've always using this with DataTables, it's the way the builded filter/sort string works that "force" me to use DataTable binded. Sorry about that.

      Delete
  44. Hi Davide,

    Thanks for the cool tool.
    but i still couldn't able to filter column (date time)
    i am using the latest version
    here is screen shots
    https://i.imgur.com/Axrkbvf.png
    https://i.imgur.com/1joRw8R.png

    screen shot of my DB
    https://i.imgur.com/DXDAWTw.png

    date example
    2016-10-30 20:44:36.000

    ReplyDelete
    Replies
    1. Hello, thank you. It should work that way, the converted filter string seems right to me. Have you check the sample project, does it work there?

      Delete
    2. i don't have jet
      so i used sql db connection directly

      Delete
    3. filter must use only date format not datetime
      it must be ((Convert([CreationDate], 'System.String') LIKE '%01/11/2016%')

      NOT
      ((Convert([CreationDate], 'System.String') LIKE '%01/11/2016 12:00:00 AM%')

      Delete
    4. i solved it
      file menustrp.cs

      i changed to this new line
      DateTime dt = (DateTime)n.Value;
      string DTStr = Convert.ToDateTime(dt).ToString("dd/MM/yyyy");
      sb.Append("(Convert([{0}], 'System.String') LIKE '" + DTStr + "%')" + appx);

      // instead of
      // sb.Append("(Convert([{0}], 'System.String') LIKE '%" + Convert.ToString((IsFilterDateAndTimeEnabled ? dt : dt.Date), CultureInfo.CurrentCulture) + "%')" + appx);

      Delete
    5. Hello and thank you for sharing your fix here, it may helps other people!

      Delete
  45. Hi Davide, I followed the video but the ADGV doesn't seem to fully implement INSERT, UPDATE, DELETE functionality. Does the tool automatically perform these or do I need to write code to implement?

    ReplyDelete
    Replies
    1. Hello, the advanced datagridview doe not implement INSERT, UPDATE, DELELE, you have to code it on you program.

      Delete
  46. Hi David,
    I'm testing your powerful datagridview, but if I have one column filter active, when I edit the cell with a value not in filter selection, the row disappear immediatly. Can I edit the cells and coonfirm or validate any modified values with one external button event ?
    In Excel, with apllied filter, not disapperaing rows on cell edit action, only after refiltering.

    Many thanks

    ReplyDelete
    Replies
    1. Hello, if I've understand what you want, you have to code a little to obrain this beyavior. That's because the filter is fixed, it's not dynamic, it means that it does not change depenging on the filtered rows.

      Delete
  47. Hi Davide, any help for this error?
    error BC30002: Type 'Zuby.ADGV.AdvancedDataGridView' is not defined.
    My project is written in VB.

    ReplyDelete
    Replies
    1. Hello, take a look at google searching error BC30002.
      What i think is that the type is not accessible to the reference.

      Delete
    2. Thanks for your reply.
      I have solved the problem ady :)

      Delete
  48. Hello iam new in c# and i fill datagrid from a datatable how can i filter and sort without databinding or how can i i convert datatable to a bindingsource
    Thank you

    ReplyDelete
    Replies
    1. Hello, take a look here, it may help you: https://github.com/davidegironi/advanceddatagridview/issues/24

      Delete
  49. Dear Davide,

    The advancedDataGridView is working well, but how can i connect it with the advancedsearching toolbar?

    ReplyDelete
    Replies
    1. Hello, take a view at the Sample project, there you can find an example to make the toolbar works.

      Delete
  50. Davide,
    my email is the following:
    rodriguez.fa114@gmail.com

    ReplyDelete
  51. Think that the first comment dont was inserted, i write again:

    Hello davide,
    You are amazing, this job is wonderful. Thank you very much.
    I tried to adapt it to my project by installing package v1.1.24722.8 (I think this is the latest version) and it works successfully, filter and sort correctly. But I have two little problems:
    1) How can I change the language? I am Spanish speaking.
    2) When I sort or filter data with DataTime type (for example) the description is not correct. The same is shown for the types of texts (Order A to Z). The same happens for the rest of the types (bool, decimal, etc.)
    Please could you help me with these two little problems?

    Thanks in advance, I hope you can read me and I look forward to your comments.
    Thank you!

    ReplyDelete
    Replies
    1. Hello Federico, thank you.
      1) look at the AdvancedDataGridViewSample Project. Here you will find a lang.json file. Translate it in your language, then you can set the language by using the commands (last one is for Search ToolBar) AdvancedDataGridView.SetTranslations(AdvancedDataGridView.LoadTranslationsFromFile("lang.json"));
      AdvancedDataGridViewSearchToolBar.SetTranslations(AdvancedDataGridViewSearchToolBar.LoadTranslationsFromFile("lang.json"));
      2) I don't understand what's the problem, sorry.

      Delete

    2. Hi davide
      Everything works perfectly, don't worry about the second point, it could be solved.
      Again, thank you very much for your input, this work is impressive.
      Regards!

      Delete
    3. Hi Please,
      Where can I find the lang.json in FRENCH
      regards

      Delete
    4. Hello,
      you have to translate it. If you do this, please share the file in the git issue repository. Thanks

      Delete
  52. Super job!!
    I had a problem with columns filter and sorting, but I figure that out.
    I have one question/problem. I'm loading data for an excel spreadsheet (no problem there). In the searchtoolbar, the combobox, I expected it to populate from the column headers, but it didn't. Do I need call an event or something? Thanks in advance.

    ReplyDelete
    Replies
    1. Thank you Aaron. To set the columns on the advanceddatagridviewseaechtoolbar you have to call the SetColumns method of the searchtoolbar passing the columns array you can get calling the .Columns property of the datagridview. You can find an example in the Sample project you can get in GitHub. Hope this helps.

      Delete
  53. This comment has been removed by the author.

    ReplyDelete
  54. Hi all, not sure if it was already addressed, here follow the code I have.

    if (cboSelector.SelectedItem.ToString() != "All")
    {
    string myTestFilter = "(Convert([MyColumn],System.String) IN ('" + cboSelector.SelectedItem.ToString() + "'))";
    dg.LoadFilterAndSort(myTestFilter, "" );

    }
    else
    {
    dg.CleanFilter();

    }

    ReplyDelete
  55. Hi, I'm using your Advanced Grid and everything works fine.
    Now I try to add localization for German language. Most translations work fine. However those in the menustrip do not change. As example my translation for ADGVSortTextASC never shows up. Those in the toolbar and the Formcustomfilter work fine.
    Is this possibly a bug or where am I on the wrong track?

    ReplyDelete
  56. Sorry - forget the previous comment. There was a missing colon in my German language file and there is something in my logic. On second load of my form everything is fine. Need to change the sequence of events.

    ReplyDelete
  57. Hello Davide,
    I had created a WinForm with several grids of type datagridview (dgv) that include a simple filtering option. Nonetheless, a user asked if the filtering option can resemble that of Excel.
    Thankfully, I came across your AdvancedDtaGridView. Great job by the way.
    So, thanks to your grid, and after making a few adjustments, it is working as before with one small issue so far:
    I'm adding a handler to the grid to add numbers to the header rows. It is the same code I used before (and still works using the original dgv) but I'm now getting this error:
    Exception thrown: 'System.ArgumentOutOfRangeException' in mscorlib.dll
    Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index

    I've debug/stepped thru the code many times at no avail. I wonder if there is a setting I need to set or if it does not work with your version of the grid?
    here is my piece of code:
    Dim adgv As AdvancedDataGridView = sender
    Dim row As DataGridViewRow

    If adgv.RowCount > 1 Then

    For Each row In adgv.Rows
    row.HeaderCell.Value = (row.Index + 1).ToString()
    Next
    End If

    it errors in the row.HeaderCell.Value line.

    Any help would be greatly appreciated as I am already thankful to you for sharing your ADGV.
    Yolanda

    ReplyDelete
    Replies
    1. Hello Yolanda, please provide a sample solution to check the error.

      Delete
    2. Hello Davide,
      Sorry for the delay in getting you a sample solution.
      I've created a form with 2 grids for comparison.
      I'm attaching the solution in a zip file.
      Thanks in advance for your help,
      Yolanda

      Delete
    3. not sure the zip file got attached as I don't see it in my previous reply. But Here is the code of the 2 grids I added to a form:
      Public Class FrmADGV
      Private Sub FrmADGV_Load(sender As Object, e As EventArgs) Handles Me.Load
      '/* Load grid

      adgv.Columns.Clear()
      Dim newTable As New DataTable

      newTable.Columns.Add("Column1")
      newTable.Columns.Add("Column2")
      newTable.Columns.Add("Column3")

      newTable.Rows.Add("a", "b", "c")
      newTable.Rows.Add("a", "b", "c")
      newTable.Rows.Add("a", "b", "c")

      adgv.DataSource = newTable
      dgv.DataSource = newTable

      End Sub

      Private Sub adgv_RowsAdded(sender As Object, e As DataGridViewRowsAddedEventArgs) Handles adgv.RowsAdded
      Try
      Dim row As DataGridViewRow
      Dim iRow As Integer = 1

      For Each row In adgv.Rows
      row.HeaderCell.Value = (iRow).ToString
      row.HeaderCell.Style.ForeColor = Color.Red
      iRow += 1
      Next

      Catch ex As Exception

      MessageBox.Show("Error in adgv_RowsAdded: " & ex.Message)

      End Try
      End Sub

      Private Sub dgv_RowsAdded(sender As Object, e As DataGridViewRowsAddedEventArgs) Handles dgv.RowsAdded
      Try
      Dim row As DataGridViewRow
      Dim iRow As Integer = 1

      For Each row In dgv.Rows
      row.HeaderCell.Value = (iRow).ToString
      row.HeaderCell.Style.ForeColor = Color.Red
      iRow += 1
      Next

      Catch ex As Exception

      MessageBox.Show("Error in dgv_RowsAdded: " & ex.Message)

      End Try
      End Sub
      End Class

      thanks again,
      Yolanda

      Delete
    4. Hello, think this is something related to the For Each loop you are doing. You have to debug it with you VS.

      Delete
    5. I'm also experiencing this Exception problem with row.HeaderCell.Value. I did a side-by-side test with DataGridView and AdvancedDataGridView, code used on both is identical.

      Delete
    6. You can start from the sample project in the github solution, and check from there. Also you can take a look at how it is used in DentneD https://github.com/davidegironi/dentned

      Delete
  58. I found the solution to the problem... In AdvancedDataGridView.cs line 1118 I added a line so that it now looks like this:

    protected override void OnCellValueChanged(DataGridViewCellEventArgs e)
    {
    if (e.ColumnIndex == -1) return;
    _filteredColumns.Remove(Columns[e.ColumnIndex].Name);
    base.OnCellValueChanged(e);
    }

    but I was poking around.

    ReplyDelete
    Replies
    1. Thank you for your post! I think I will add this line in the offical distribution too! It makes sense.

      Delete
    2. Hi Davide, I thought a bit more about it but have not had the chance to test. Perhaps consider this...?

      protected override void OnCellValueChanged(DataGridViewCellEventArgs e)
      {
      if (e.ColumnIndex >= 0)
      {
      _filteredColumns.Remove(Columns[e.ColumnIndex].Name);
      }
      base.OnCellValueChanged(e);
      }

      Delete
    3. Hello, this makes even more sense. I think I'll go for if if (e.RowIndex >= 0 && e.ColumnIndex >= 0) and also for (e.RowIndex >= 0) added on OnRowsAdded and OnRowsRemoved, if you can test this it will be really good.

      Delete