Ja ate cfare e shkrova me larte.
Kur shtyp ComboBox, shfaqet nje forme nder ComboBox, si t'ishte pjese e ComboBox-it se bashku me nje DataGridView te integruar:

Kurse kur e selekton nje Rekord, duke bere nje DoubleKlick ne nje Cell te DataGridView:

Emri dhe Mbiemri i selektuar nga DataGridView si Liste, te shfaqet ne Labelin e Formes se pare [Parent].
Me kete Emer dhe Mbiemer mund te procesosh me tutje, cfaredo qe te duash.
Kodi i formes primare [Form1]:
Kodi:
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace testCombo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void comboBox1_MouseClick(object sender, MouseEventArgs e)
{
DataTable dt = GetTableFilled();
Point location = comboBox1.PointToScreen(Point.Empty);
using (DGVList dgl = new DGVList(dt))
{
dgl.SetDesktopLocation(location.X, location.Y + 22);
dgl.Size = new Size(comboBox1.Width, 200);
DialogResult dlgres = dgl.ShowDialog(this);
if (dlgres == DialogResult.OK)
{
label1.Text = "Zgjodhe rekordin: \n" + dgl._Name + " " + dgl._Lastname;
}
dgl.Dispose();
}
}
private DataTable GetTableFilled()
{
DataTable dt = new DataTable();
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("lastname", typeof(string));
dt.Rows.Add(new object[] { "TOM", "JERRY" });
dt.Rows.Add(new object[] { "SCOOBY", "DOO" });
dt.Rows.Add(new object[] { "MICKEY", "MOUSE" });
return dt;
}
}
}
Kodi i formes se dyte, qe shfaqet ne vend te ComboBox-it:
Kodi:
using System.Data;
using System.Windows.Forms;
namespace testCombo
{
public partial class DGVList : Form
{
string _name;
string _lastname;
public DGVList(DataTable dt)
{
InitializeComponent();
this.dataGridView1.DataSource = dt;
this.dataGridView1.Focus();
}
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
{
this._Name = this.dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
this._Lastname = this.dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
this.DialogResult = DialogResult.OK;
this.Close();
}
}
public string _Name { get { return this._name; } set { this._name = value; } }
public string _Lastname { get { return this._lastname; } set { this._lastname = value; } }
}
}
Programi i kompiluar si ZIP, mund ta provosh nese ke .NET 4.0:
Combo.zip
Krijoni Kontakt