Garry's Mod Wiki

DListView

Description

A data view with rows and columns.

View source

Parent

Derives methods, etc not listed on this page from DPanel.

Events

DListView:DoDoubleClick( number lineID, Panel line )
Called when a line in the DListView is double clicked.
DListView:OnRowRightClick( number lineID, Panel line )
Called when a row is right-clicked
DListView:OnRowSelected( number rowIndex, Panel row )
Called internally by DListView:OnClickLine when a line is selected. This is the function you should override to define the behavior when a line is selected.

Methods

Panel DListView:AddColumn( string column, number position = nil )
Adds a column to the listview.
Panel DListView:AddLine( vararg text )
Adds a line to the list view.
DListView:ClearSelection()
Clears the current selection in the DListView.
number DListView:ColumnWidth( number column )
Gets the width of a column.
number DListView:DataLayout()
Creates the lines and gets the height of the contents, in a DListView.
DListView:DisableScrollbar()
Removes the scrollbar.
DListView:FixColumnsLayout()
This is used internally - although you're able to use it you probably shouldn't. Internal helper function called from the PANEL:PerformLayout of DListView.
Panel DListView:GetCanvas()
Gets the canvas.
number DListView:GetDataHeight()
Returns the height of the data of the DListView. See also DListView:SetDataHeight.
boolean DListView:GetDirty()
This is used internally - although you're able to use it you probably shouldn't. See DListView:SetDirty.
Returns the height of the header of the DListView. See also DListView:SetHeaderHeight.
Returns whether the header line should be visible on not.
number DListView:GetInnerTall()
Returns the height of DListView:GetCanvas. Intended to represent the height of all data lines.
Panel DListView:GetLine( number id )
Gets the DListView_Line at the given index.
table DListView:GetLines()
Gets all of the lines added to the DListView.
Returns whether multiple lines can be selected or not. See DListView:SetMultiSelect.
table DListView:GetSelected()
Gets all of the lines that are currently selected.
Gets the currently selected DListView_Line index. If DListView:SetMultiSelect is set to true, only the first line of all selected lines will be returned. Use DListView:GetSelected instead to get all of the selected lines.
boolean DListView:GetSortable()
Returns whether sorting of columns by clicking their headers is allowed or not. See also DListView:SetSortable.
number DListView:GetSortedID( number lineId )
This is used internally - although you're able to use it you probably shouldn't. Converts LineID to SortedID
DListView:OnClickLine( Panel line, boolean isSelected )
This is used internally - although you're able to use it you probably shouldn't. Use DListView:OnRowSelected instead! Called whenever a line is clicked.
DListView:OnRequestResize( Panel column, number size )
This is used internally - although you're able to use it you probably shouldn't. Called from DListView_Column.
DListView:RemoveLine( number line )
Removes a line from the list view.
DListView:SelectFirstItem()
Selects the line at the first index of the DListView if one has been added.
DListView:SelectItem( Panel Line )
Selects a line in the listview.
DListView:SetDataHeight( number height )
Sets the height of all lines of the DListView except for the header line. See also DListView:SetHeaderHeight.
DListView:SetDirty( boolean isDirty )
This is used internally - although you're able to use it you probably shouldn't. Used internally to signify if the DListView needs a rebuild.
DListView:SetHeaderHeight( number height )
Sets the height of the header line of the DListView. See also DListView:SetDataHeight.
DListView:SetHideHeaders( boolean hide )
Sets whether the header line should be visible on not.
DListView:SetMultiSelect( boolean allowMultiSelect )
Sets whether multiple lines can be selected by the user by using the ctrl or ⇧ shift keys. When set to false, only one line can be selected.
DListView:SetSortable( boolean isSortable )
Enables/disables the sorting of columns by clicking. This will only affect columns that are created after this function is called. Existing columns will be unaffected.
DListView:SortByColumn( number columnIndex, boolean descending = false )
Sorts the items in the specified column.
DListView:SortByColumns( number column1 = nil, boolean descrending1 = false, number column2 = nil, boolean descrending2 = false, number column3 = nil, boolean descrending3 = false, number column4 = nil, boolean descrending4 = false )
Sorts the list based on given columns. All arguments are optional

Example

Creates a DListView and populates it with two columns and three items, only one of which can be selected at a time.

Selecting a row will print a console message containing the text of the row and its index.

local f = vgui.Create( "DFrame" ) f:SetSize( 500, 500 ) f:Center() f:MakePopup() local AppList = vgui.Create( "DListView", f ) AppList:Dock( FILL ) AppList:SetMultiSelect( false ) AppList:AddColumn( "Application" ) AppList:AddColumn( "Size" ) AppList:AddLine( "PesterChum", "2mb" ) AppList:AddLine( "Lumitorch", "512kb" ) AppList:AddLine( "Troj-on", "661kb" ) AppList.OnRowSelected = function( lst, index, pnl ) print( "Selected " .. pnl:GetColumnText( 1 ) .. " ( " .. pnl:GetColumnText( 2 ) .. " ) at index " .. index ) end
Output:
Selected PesterChum ( 2mb ) at index 1 Selected Lumitorch ( 512kb ) at index 2 Selected Troj-on ( 661kb ) at index 3