Search Unity

How we use ListView in the Unity ?????????????

Discussion in 'Immediate Mode GUI (IMGUI)' started by achingupta87, Jun 7, 2012.

  1. achingupta87

    achingupta87

    Joined:
    Apr 9, 2012
    Posts:
    144
    Hello EveryBody

    I wants to use Listview in my project . But in c# listview is find in System.Windows.Forms namespace which is not include in mondevelop in the unty.

    How It is possible That I canuse Listview in Unity.....Please help


    Thanks
     
  2. UnityDigger

    UnityDigger

    Joined:
    Nov 20, 2011
    Posts:
    79
    There is no direct solution. Windows.Forms.* is not included into Unity3D coz it is platform-specific a lot.
    Try to play with GUI.SelectionGrid.
     
  3. ModStoryGames

    ModStoryGames

    Joined:
    Apr 27, 2012
    Posts:
    179
    It's not terribly difficult to create your own list view. All it takes is a list of items and a loop in OnGUI.

    Code (csharp):
    1.  
    2. List<GUIContent> items;
    3. Vector2 scrollVector;
    4. void OnGUI()
    5. {
    6.     GUILayout.BeginHorizontal(GUI.skin.box);
    7.     scrollVector = GUILayout.BeginScrollView(scrollVector);
    8.     for (int i = 0; i < items.Count; i++)
    9.     {
    10.         GUILayout.Label(items[i]);
    11.         if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
    12.         {
    13.             // Handle events here
    14.         }
    15.     }
    16.     GUILayout.EndScrollView();
    17.     GUILayout.EndHorizontal();
    18. }
    19.  
    This is the basis for how pages are drawn in my editor extension Asset+. :D
     
    Oxygeniium likes this.
  4. achingupta87

    achingupta87

    Joined:
    Apr 9, 2012
    Posts:
    144
    Thanks for your reply.......But Eddy I am facing some problem when I try to use your code Its gives some error message.
    It is not able to find namespace for List.

    This is error message-: The type or namespace name `List`1' could not be found. Are you missing a using directive or an assembly reference?

    Please help how we solve this.
     
  5. UnityDigger

    UnityDigger

    Joined:
    Nov 20, 2011
    Posts:
    79
    using System.Collections.Generic; // hope it helps ;-)
     
  6. GrantTheAnt

    GrantTheAnt

    Joined:
    Jan 13, 2013
    Posts:
    19