Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can query from different datasource and dump it in a single collection type and bind to combobox. </p> <p><strong>Here is a sample code, you can do something similar to this</strong> using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Windows.Forms;</p> <pre><code>namespace WindowsFormsApplication1 { public partial class Form1 : Form { List&lt;Item&gt; items; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //Let's say we are getting items from two different datasources and putting them in a same collection items = new List&lt;Item&gt;(); //Getting pens from dataSource1 items.Add (new Pen("Parker",Color.Blue )); items.Add(new Pen("Paper Mate", Color.Blue)); //Adding Books from dataSource2 items.Add(new Book("Programming in C", Color.Red)); items.Add(new Book("Design Patterns", Color.Red)); //Data binding comboBox1.DataSource = items; comboBox1.DisplayMember = "Name"; comboBox1.ValueMember = "Color"; this.comboBox1.DrawMode = DrawMode.OwnerDrawFixed; //Do not forget this } private void comboBox1_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); int index = e.Index; Item item = comboBox1.Items[index] as Item ; if (item.Color.Equals ( Color.Red)) e.Graphics.DrawString(item.Name, this.Font , Brushes.Red, new Point(e.Bounds.X, e.Bounds.Y)); else if (item.Color.Equals ( Color.Blue)) e.Graphics.DrawString(item.Name, this.Font, Brushes.Blue, new Point(e.Bounds.X, e.Bounds.Y)); else e.Graphics.DrawString(item.Name, this.Font, Brushes.Black, new Point(e.Bounds.X, e.Bounds.Y)); } } public abstract class Item { string name; Color color; public string Name { get { return name; } set { name = value; } } public Color Color { get { return color; } set { color = value; } } } public class Book:Item { public Book(string name, Color color){ this.Name = name; this.Color = color; } } public class Pen : Item { public Pen(string name, Color color){ this.Name = name; this.Color = color; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload