grid.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: grid.h
  3. // Purpose: topic overview
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @page overview_grid wxGrid Overview
  9. @tableofcontents
  10. wxGrid and its related classes are used for displaying and editing tabular
  11. data. wxGrid supports custom attributes for the table cells, allowing to
  12. completely customize its appearance and uses a separate grid table
  13. (wxGridTableBase-derived) class for the data management meaning that it can be
  14. used to display arbitrary amounts of data.
  15. @section overview_grid_simpleexample Getting Started
  16. For simple applications you need only refer to the wxGrid class in your code.
  17. This example shows how you might create a grid in a frame or dialog constructor
  18. and illustrates some of the formatting functions.
  19. @code
  20. // Create a wxGrid object
  21. grid = new wxGrid( this,
  22. -1,
  23. wxPoint( 0, 0 ),
  24. wxSize( 400, 300 ) );
  25. // Then we call CreateGrid to set the dimensions of the grid
  26. // (100 rows and 10 columns in this example)
  27. grid->CreateGrid( 100, 10 );
  28. // We can set the sizes of individual rows and columns
  29. // in pixels
  30. grid->SetRowSize( 0, 60 );
  31. grid->SetColSize( 0, 120 );
  32. // And set grid cell contents as strings
  33. grid->SetCellValue( 0, 0, "wxGrid is good" );
  34. // We can specify that some cells are read->only
  35. grid->SetCellValue( 0, 3, "This is read->only" );
  36. grid->SetReadOnly( 0, 3 );
  37. // Colours can be specified for grid cell contents
  38. grid->SetCellValue(3, 3, "green on grey");
  39. grid->SetCellTextColour(3, 3, *wxGREEN);
  40. grid->SetCellBackgroundColour(3, 3, *wxLIGHT_GREY);
  41. // We can specify the some cells will store numeric
  42. // values rather than strings. Here we set grid column 5
  43. // to hold floating point values displayed with width of 6
  44. // and precision of 2
  45. grid->SetColFormatFloat(5, 6, 2);
  46. grid->SetCellValue(0, 6, "3.1415");
  47. @endcode
  48. Here is a list of classes related to wxGrid:
  49. @li wxGrid: The main grid control class itself.
  50. @li wxGridTableBase: The base class for grid data provider.
  51. @li wxGridStringTable: Simple wxGridTableBase implementation supporting only
  52. string data items and storing them all in memory (hence suitable for not
  53. too large grids only).
  54. @li wxGridCellAttr: A cell attribute, allowing to customize its appearance as
  55. well as the renderer and editor used for displaying and editing it.
  56. @li wxGridCellAttrProvider: The object responsible for storing and retrieving
  57. the cell attributes.
  58. @li wxGridColLabelWindow: The window showing the grid columns labels.
  59. @li wxGridRowLabelWindow: The window showing the grid rows labels.
  60. @li wxGridCornerLabelWindow: The window used in the upper left grid corner.
  61. @li wxGridWindow: The window representing the main part of the grid.
  62. @li wxGridCellRenderer: Base class for objects used to display a cell value.
  63. @li wxGridCellStringRenderer: Renderer showing the cell as a text string.
  64. @li wxGridCellNumberRenderer: Renderer showing the cell as an integer number.
  65. @li wxGridCellFloatRenderer: Renderer showing the cell as a floating point
  66. number.
  67. @li wxGridCellBoolRenderer: Renderer showing the cell as checked or unchecked
  68. box.
  69. @li wxGridCellEditor: Base class for objects used to edit the cell value.
  70. @li wxGridCellStringEditor: Editor for cells containing text strings.
  71. @li wxGridCellNumberEditor: Editor for cells containing integer numbers.
  72. @li wxGridCellFloatEditor: Editor for cells containing floating point numbers.
  73. @li wxGridCellBoolEditor: Editor for boolean-valued cells.
  74. @li wxGridCellChoiceEditor: Editor allowing to choose one of the predefined
  75. strings (and possibly enter new one).
  76. @li wxGridEvent: The event sent by most of wxGrid actions.
  77. @li wxGridSizeEvent: The special event sent when a grid column or row is
  78. resized.
  79. @li wxGridRangeSelectEvent: The special event sent when a range of cells is
  80. selected in the grid.
  81. @li wxGridEditorCreatedEvent: The special event sent when a cell editor is
  82. created.
  83. @li wxGridSelection: The object efficiently representing the grid selection.
  84. @li wxGridTypeRegistry: Contains information about the data types supported by
  85. the grid.
  86. @section overview_grid_resizing Column and Row Sizes
  87. @b NB: This section will discuss the resizing of wxGrid rows only to avoid
  88. repetitions but everything in it also applies to grid columns, just replace @c
  89. Row in the method names with @c Col.
  90. Initially all wxGrid rows have the same height, which can be modified for all
  91. of them at once using wxGrid::SetDefaultRowSize(). However, unlike simpler
  92. controls such as wxListBox or wxListCtrl, wxGrid also allows its rows to be
  93. individually resized to have their own height using wxGrid::SetRowSize() (as a
  94. special case, a row may be hidden entirely by setting its size to 0, which is
  95. done by a helper wxGrid::HideRow() method). It is also possible to resize a row
  96. to fit its contents with wxGrid::AutoSizeRow() or do it for all rows at once
  97. with wxGrid::AutoSizeRows().
  98. Additionally, by default the user can also drag the row separator lines to
  99. resize the rows interactively. This can be forbidden completely by calling
  100. wxGrid::DisableDragRowSize() or just for the individual rows using
  101. wxGrid::DisableRowResize().
  102. If you do allow the user to resize the grid rows, it may be a good idea to save
  103. their heights and restore it when the grid is recreated the next time (possibly
  104. during a next program execution): the functions wxGrid::GetRowSizes() and
  105. wxGrid::SetRowSizes() can help with this, you will just need to serialize
  106. wxGridSizesInfo structure returned by the former in some way and deserialize it
  107. back before calling the latter.
  108. */