Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
290
WinGrid creating a default row when bind collection is zero
posted

Hi, 

When having no data in my own IBind collection on form load, I bind the collection using the function wingrid.SetDataBinding(collection, null, true); via the run-time. However, the collection then comes back with having an object in it ( therefore the count = 1) and therefore a blank row is created.

is there a way for the grid from preventing this behaviour when the collection is 0 before the bind?

Note: When there is data before the bind. i.e. data from the back-end..the grid works perfectly by only creating 1 row per object inside the collection, but if there is no data from the backend, the above happens.

Thanks

Chris 

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    Hi Chris,

    The grid doesn't create any new rows. What's probably happening here is that the grid is asking the DotNet BindingManager for the structure of the data so that the grid can build the bands and columns. If there are no rows in the data source and the data source doesn't expose the structure, the BindingManager will create a new row, get the structure from that row, and then cancel it. Of course, if your data source doesn't support cancelling new rows, that row will stay around.

    I recommend using a BindingList<T> or some derived types as your data source. That will save you a lot of headaches. But if you are writing your own data source from scratch and implementing IBindingList or IList, then you will probably need to implement some other interfaces to make things work properly, like ITypedList and/or IEditableObject and/or ICancelAddNew.

Children