• North American Sales: 1-800-231-8588
  • Global Contacts
  • My Account
Infragistics Infragistics
Menu
  • North American Sales: 1-800-321-8588
  • My Account
    • Sign In/Register
  • Design & DevelopmentDesign & Develop
    • Best Value
      Infragistics Ultimate The complete toolkit for building high performing web, mobile and desktop apps.
      Indigo.Design Use a unified platform for visual design, UX prototyping, code generation and application development.
    • Web
      Ignite UI for Angular Ignite UI for JavaScript Ignite UI for React Ultimate UI for ASP.NET Indigo.Design
    • Desktop
      Ultimate UI for Windows Forms Ultimate UI for WPF
      Prototyping
      Indigo.Design
    • Mobile
      Ultimate UI for Xamarin Ultimate UI for iOS Ultimate UI for Android
    • Automated Testing Tools
      Test Automation for Micro Focus UFT: Windows Forms Test Automation for Micro Focus UFT: WPF Test Automation for IBM RFT: Windows Forms
  • UX
    • Indigo.Design Desktop Collaborative prototyping and remote usability testing for UX & usability professionals
    • Indigo.Design A Unified Platform for Visual Design, UX Prototyping, Code Generation, and App Development
  • Business Intelligence
    • Reveal Embedded Accelerate your time to market with powerful, beautiful dashboards into your apps
    • Reveal App Empower everyone in your organization to use data to make smarter business decisions
  • Team Productivity
  • Learn & Support Support
    • Help & Support Documents
    • Blogs
    • Forums
    • Product Ideas
    • Reference Applications
    • Customer Stories
    • Webinars
    • eBook & Whitepapers
    • Events
  • Free Trials
  • Pricing
    • Product Pricing / Buy Online
    • Renew Existing License
    • Contact Us
Windows Forms
  • Product Platforms
  • More
Windows Forms
Windows Forms Best Practices for Placing a DropDown or Combo in an WinGrid Cell
  • Blog
  • Files
  • Wiki
  • Members
  • Mentions
  • Tags
  • More
  • Cancel
  • New
Windows Forms requires membership for participation - click to join
  • Windows Forms
  • Best Practices for Placing a DropDown or Combo in an WinGrid Cell
  • Change Color of Column Headers in WinGrid
  • Disable WinGrid Row, Cell or Column with Activation Object
  • Performance in the WinTilePanel
  • Select All Rows in WinGrid Programatically
  • UI Thread Marshaling in the Model Layer
  • Using an WinGrid DataFilter to Convert Strings to Bools (and vice-versa) for a Checkbox Column

Best Practices for Placing a DropDown or Combo in an WinGrid Cell

Best Practices for Placing a DropDown or Combo in an WinGrid Cell

Summary

It is often desirable to place a dropdown list of choices in a cell of the grid. This has several advantages:

  1. The user can drop down a list and pick one of several options.
  2. The dropdown list can act as a lookup table to convert ID values into more user-friendly display text.
  3. The dropdpown list can limit the user to a specific set of choices without permitting entry of invalid values.

Additional Information

There are several different ways to attach a list of values to a grid column. The simplest of these is the ValueList property of the Column. The ValueList property of a column or cell can accept any object which implements the IValueList interface, such as a ValueList object or an UltraDropDown control. The UltraCombo control also implements IValueList, but it is generally desirable to use UltraDropDown instead of UltraCombo, because it has less overhead.

ValueList

The ValueList is a very simple, light, and easy-to-use object. You can create a ValueList by using the ValueLists collection on the grid's DisplayLayout. Each ValueListItem has a DataValue and a DisplayText, so the ValueList can translate ID's into user-friendly text. The ValueList displays only a single column of values with no column header, much like the Microsoft ComboBox. ValueLists cannot be bound, they must be populated manually either at design-time or run-time.

ValueList in VB:

Private Sub UltraGrid1_InitializeLayout(ByVal sender As System.Object, _
    ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) _
    Handles UltraGrid1.InitializeLayout
    
    Dim vl As ValueList 

        If (Not e.Layout.ValueLists.Exists("MyValueList")) Then
            vl = e.Layout.ValueLists.Add("MyValueList")
            vl.ValueListItems.Add(1, "A")
            vl.ValueListItems.Add(2, "B")
            vl.ValueListItems.Add(3, "C")
        End If 

        e.Layout.Bands(0).Columns("Int32 1").ValueList = e.Layout.ValueLists("MyValueList") 

End Sub

ValueList in C#:

private void ultraGrid1_InitializeLayout(object sender, 
    Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
    ValueList vl;
    if ( ! e.Layout.ValueLists.Exists("MyValueList"))
    {
        vl = e.Layout.ValueLists.Add("MyValueList");
        vl.ValueListItems.Add(1, "A");
        vl.ValueListItems.Add(2, "B");
        vl.ValueListItems.Add(3, "C");
    }
    e.Layout.Bands[0].Columns["Int32 1"].ValueList = e.Layout.ValueLists["MyValueList"];
}

UltraDropDown

UltraDropdown is a much more powerful ValueList. It is essentially a dropdown UltraWinGrid (although it is limited to a single band). Just like the WinGrid, it must be bound and has a wide range of Appearances and features such as sorting, filtering and resizable columns. It can display multiple columns, just like the WinGrid. To translate ID's into user-friendly text, set the ValueMember and DisplayMember properties which detmermine the ID and text columns respectively.

UltraDropDown in VB:

Private Sub Form1_Load(ByVal sender As System.Object, _
          ByVal e As System.EventArgs) Handles MyBase.Load
        Me.BindUltraDropDown()
End Sub 

Private Sub BindUltraDropDown() 

        Dim dt As DataTable = New DataTable()
        dt.Columns.Add("ID", GetType(Integer))
        dt.Columns.Add("DisplayText", GetType(String)) 

        dt.Rows.Add(New Object() {1, "A"})
        dt.Rows.Add(New Object() {2, "B"})
        dt.Rows.Add(New Object() {3, "C"})
        dt.AcceptChanges() 

        Me.UltraDropDown1.SetDataBinding(dt, Nothing)
        Me.UltraDropDown1.ValueMember = "ID"
        Me.UltraDropDown1.DisplayMember = "DisplayText"
End Sub 

Private Sub UltraGrid1_InitializeLayout(ByVal sender As System.Object, _
        ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) _
        Handles UltraGrid1.InitializeLayout
        
        e.Layout.Bands(0).Columns("Int32 1").ValueList = Me.UltraDropDown1
End Sub

UltraDropDown in C#:

private void Form1_Load(object sender, System.EventArgs e)
{            
    this.BindUltraDropDown();
} 

private void BindUltraDropDown()
{
    DataTable dt = new DataTable();
    dt.Columns.Add("ID", typeof(int));
    dt.Columns.Add("DisplayText", typeof(string)); 

    dt.Rows.Add(new object[] {1, "A"});
    dt.Rows.Add(new object[] {2, "B"});
    dt.Rows.Add(new object[] {3, "C"});
    dt.AcceptChanges(); 

    this.ultraDropDown1.SetDataBinding(dt, null);
    this.ultraDropDown1.ValueMember = "ID";
    this.ultraDropDown1.DisplayMember = "DisplayText";
} 

private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{            
    e.Layout.Bands[0].Columns["Int32 1"].ValueList = this.ultraDropDown1;
}

UltraCombo

The UltraCombo can be used as a ValueList and it has essentially the same features as UltraDropDown. However, UltraCombo is intended for use as a standalone ComboBox. So while it can be used as a ValueList, there is no reason to do so. It has no advantage over UltraDropDown and has greater overhead.

In addition to being an IValueList, the UltraCombo is also an Editor. So it can also be assigned as the EditorControl of a column. This has certain advantages over the UltraDropDown, such as the ability to use a DataFilter or provide EditorButtons. But if you are not using these features, the extra overhead of UltraCombo means that the UltraDropDown is a better choice.

DropDownStyle

By default, when a ValueList is attached to a grid column, the user may choose an item from the list or may type into the cell. The grid will attempt to find the closest matching item on the list and fill in the cell (AutoComplete). If no match is found, the user may enter text that does not exist on the list. To prevent this, set the DropDownStyle property of the grid column to DropDownList. This will prevent the user from typing into the cell, although the keyboard will still function for searching through the list.

  • WinCombo
  • WinDropDown
  • WinGrid
  • Share
  • History
  • More
  • Cancel
Related
Recommended