Home Forums WinForms controls Xceed Grid for WinForms Filtering one ComboBox cell by another in a grid Reply To: Filtering one ComboBox cell by another in a grid

User (Old forums)
Member
Post count: 23064

Hi,

I think I have found a sample project (in VB.NET) that does what you want.  I will let you be the judge.  I’ve just realized that there is no grid in this is example, only two wincombobox linked together.  I’ve included the complete project. 

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports Xceed.Editors

Namespace WindowsFormsApplication35
  Partial Public Class Form1
   Inherits Form
 Public Sub New()
   InitializeComponent()
 End Sub

 Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
   Dim dataSet As New DataSet()

   Dim categories As New DataTable(“Categories”)
   Dim subCategories As New DataTable(“SubCategories”)

   categories.Columns.Add(New DataColumn(“PK”, GetType(Integer)))
   categories.Columns.Add(New DataColumn(“Name”, GetType(String)))

   subCategories.Columns.Add(New DataColumn(“PK”, GetType(Integer)))
   subCategories.Columns.Add(New DataColumn(“FK”, GetType(Integer)))
   subCategories.Columns.Add(New DataColumn(“Name”, GetType(String)))

   Dim z As Integer = 0
   For i As Integer = 0 To 2
  categories.Rows.Add(i, “Category #” & i.ToString())

  For j As Integer = 0 To 4
    subCategories.Rows.Add(z, i, “SubCategory #” & j.ToString() & ” of cat# ” & i.ToString())
    z += 1
  Next j
   Next i


   dataSet.Tables.Add(categories)
   dataSet.Tables.Add(subCategories)

   dataSet.Relations.Add(New DataRelation(“Cat_SubCat”, categories.Columns(“PK”), subCategories.Columns(“FK”)))

 


   m_winComboBoxMaster.Location = New Point(0, 50)
   m_winComboBoxChild.Location = New Point(300, 50)

 

   Me.Controls.Add(m_winComboBoxMaster)
   Me.Controls.Add(m_winComboBoxChild)


   m_winComboBoxChild.DropDownControl.BindingContext = m_winComboBoxMaster.DropDownControl.BindingContext

   m_winComboBoxMaster.SetDataBinding(dataSet, “Categories”)
   m_winComboBoxMaster.DisplayFormat = “%Name%”

   AddHandler m_winComboBoxMaster.SelectedItemChanged, AddressOf winComboBoxMaster_SelectedItemChanged

   m_winComboBoxChild.SetDataBinding(dataSet, “Categories.Cat_SubCat”)
   m_winComboBoxChild.DisplayFormat = “%Name%”

   m_winComboBoxMaster.SelectedIndex = 0
 End Sub

 Private m_winComboBoxMaster As New WinComboBox()
 Private m_winComboBoxChild As New WinComboBox()

 Private Sub winComboBoxMaster_SelectedItemChanged(ByVal sender As Object, ByVal e As EventArgs)
   m_winComboBoxChild.TextBoxArea.Text = TryCast(m_winComboBoxChild.Items(0).Values(2), String)
 End Sub
  End Class
End Namespace

Regards,

Imported from legacy forums. Posted by Ghislain (had 2072 views)