![]() The code in this example merely checks to see that the Grid’s container and the List’s container are not the same object, and then assumes the list is directly contained by the form. I suppose it would be possible to look for the list’s container if it were a different container within the same chain of nested containers, but, quite frankly, the need for this exercise escaped me. ![]() To perform this fixup, I wrote the CalcContainerOffset function (implemented in the MainForm object of the demo project), which assumes the list is a direct descendant of its form. If the grid happens to be inside of a control that is a container of other controls (for instance, a PictureBox or Frame control), we have a bit more work to do: We must walk up the container chain until we find an object that either has no container property, has no parent property, has container and parent that are the same object, or has a container of type Form/MdiForm. The code in the figure below accurately calculates the correct position, as long as the list and the grid are both immediate children of their form, or in the same container: To create this effect, the ButtonClick event handler must dynamically position a listbox just below the active cell. It’s up to your app to do anything with it. ![]() There is no functionality associated with this element by default clicking it merely fires the “ButtonClick” event. That’s where the similarity ends, though. When set to true for a given column, the cells in that column are shown with a graphical “button” drawn on the right edge, much like the element of a combobox that’s clicked to make it display its drop-down list. The Column object exposes a boolean property named Button. (I squandered many hours chasing this most irritating little flaw.) The Lookup Column It fails to retain a reference to the object on which it was implicitly called, somehow causing it to “forget” that it has already displayed the menu. Apparently, the call loses track of where it originated. If your menu item causes some other object to receive focus, the first form can cause the menu to be spuriously redisplayed. So, in a form, the two statements below would seem to be equivilent: There are two valid ways to call this: It can be called as a method of an explicitly specified object, or it can be called without an object, in which case the active form is implied. The other quirk involves the call to the VB function PopupMenu. (It does this by default for the left button.) Menus Gone Mad The Grid does fire the MouseDown event when either button is clicked, so the work-around is to explicitly set focus to the Grid in the Grid_MouseDown handler. The net effect is the user would be forced to left-click the Grid prior to right-clicking it, unless it already had focus-it makes the app look unresponsive. The Grid will not fire MouseUp for the right button unless it has focus. The MouseUp event is suitable for this purpose, but there are two little quirks you’ll need to know about. It does support a Click event, but it’s useless for this purpose because it does not identify which mouse button was clicked. The grid itself does not support a ContextMenu event, as do most other VB controls. The application that accompanies this article demonstrates all of these, and this section will hopefully explain the mechanics of each. The most notable of these would be Access-style lookup columns, boolean columns that are represented graphically as checkboxes, and the use of context menus. There are some grid-related features users have come to expect, that the DataGrid stops well short of making easy to implement.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |