I have a grid that when the window form is first loaded has a lot of horizontal scroll space on the right side of the last column. I then click the save button that goes out to the DB to get data and sets up the grid the same way as when the form first loaded but with the new row. This time the grid doesn't have any extra horizontal scroll space to the right of the last column. Why would refreshing the grid with this new row make any difference. The data is grabbed the same way and the grid is set up the same way upon loading the form as it is when any row is added.
One thing I've found is that I'm setting the datasource of the grid to a collection that has a lot of items in it. I try hidding all of these items and then only showing two of the items. Doing this gives me all of this extra horizontal space. If I set the datasource of the grid to a datatable that contains only the two columns I want to show then I don't have the extra horizontal space.
I've found a solution to the problem but was wondering why I had a problem when setting the datasource of the grid to the collection. This doesn't seem like it should happen and I shouldn't need to create a new datatable to fix this problem. Thanks for any explanation.
I had a same problem and I followed Mike's suggestion. This seemed to have work:
MyGrd.DisplayLayout.ViewStyle =
ViewStyle.SingleBand;
This issue occurs only when when you are binding to a datasource that has another collection inside it.
I created a new dataset and populated that dataset with only the fields I needed from my original collection. My collection had about 10 properties in it but I only wanted to see 3 properties in the grid. This seems like extra work I shouldn't have to do, but its the only solution I found. Hopefully this helps you.
Richdjw
You had said that you found a solution to the problem and I was wondering what that was. I am having the same issue and hidding the child bands isn't an option.
Thanks.
This is just a guess, but it sounds to me like your data structure has a child band so the grid is leaving space of it, even through there may not be any actual rows in it. Try setting the ViewStyle (on the DisplayLayout) to SingleBand if you don't want the child rows displayed.
Mike,
sorry for taking long to reply. I currently don't have a way to put up screen shots but if after this you still don't understand I'll try to get that figured out. Hopefully this will clear things up, if not let me know.
My problem is that I will set the grid datasource to the collection, hidding all but two items in the collection. When the grid is displayed I only see the two items that I wanted to see, but the edge of the last column (the second column) is still a width of 100 from reaching the far right side of the grid (thus the whole grid horizontal space is not taken up). On top of that, the horizontal scroll bar shows up and allows me to scroll about 3 times the length of the grid. Therefore I'm scrolling a bunch of empty horizontal space (no columns or anything is in this space) when it seems the grid should be smart enough to know there is nothing there (and therefore not need the horizontal scroll bar).
The wierd part is when I update the grid using the same code I used to initially set up the grid, the grid all of a sudden is smart enough to get rid of the horizontal scroll bar so I can't look at all the empty space.
Thanks for any help!