How to Bind a Combo in a Gridview

How to Bind a Combo in a Gridview thumbnail
A Grid organizes repeating data into a meaningful visual structure.

Programmers increasingly find modern computing overwhelmingly complex. To help programmers manage this complexity, Microsoft created Windows Presentation Foundation, or WPF. Among the most important of the WPF tools provided by Microsoft is the GridView tag, which can be nested inside a Grid or ListView control. The Grid control allows programmers to display values from a data source in table format. You can bind a Combo -- called a ComboBox -- using WPF XAML markup code.

Things You'll Need

  • Visual Studio
Show More

Instructions

    • 1

      Open Visual Studio and view the markup code that contains the GridView that you intend to bind.

    • 2

      Add a ComboBox onto the page. Place it within the Grid control.

    • 3

      Bind the ComboBox to the data source using the appropriate declarative syntax. Type "ItemsSource," an equal sign, and place the binding syntax within quotes:

      <ComboBox ItemsSource="{Binding}"/>

      Leave other ComboBox attributes untouched.

    • 4

      Finish adding additional items to the Grid. Add a GridView to the Grid control. Nest it within a ListView object -- which is itself nested inside a Grid object -- and bind it to the data source using the DisplayMemberBinding attribute:

      <ListView ItemsSource="{Binding Path=SalesOrderDetails}" Name="listViewItems">
      <ListView.View>
      <GridView>
      <GridViewColumn DisplayMemberBinding="{Binding Path=SamplePath}" />
      </ListView.View>
      </ListView>

    • 5

      Save your work and click on the "Debug" button to test your code and ensure it works as expected.

Related Searches:

References

  • Photo Credit Thinkstock Images/Comstock/Getty Images

Comments

Related Ads

Featured