Hi AnkitPal,
Check this example. Now please take its reference and correct your code.
Form Design
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("Id", typeof(int)), new DataColumn("Name", typeof(string)) });
dt.Rows.Add(1, "John Hammond");
dt.Rows.Add(2, "Mudassar Khan");
dt.Rows.Add(3, "Suzanne Mathews");
dt.Rows.Add(4, "Robert Schidner");
//Insert the Default Item to DataTable.
DataRow row = dt.NewRow();
row[0] = 0;
row[1] = "Please select";
dt.Rows.InsertAt(row, 0);
//Assign DataTable as DataSource.
cbCustomers.DataSource = dt;
cbCustomers.DisplayMember = "Name";
cbCustomers.ValueMember = "Id";
}
private void btnSubmit_Click(object sender, EventArgs e)
{
string message = "Name: " + cbCustomers.Text;
message += Environment.NewLine;
message += "CustomerId: " + cbCustomers.SelectedValue;
MessageBox.Show(message);
}
VB.Net
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Dim dt As DataTable = New DataTable
dt.Columns.AddRange(New DataColumn() {New DataColumn("Id", GetType(System.Int32)), New DataColumn("Name", GetType(System.String))})
dt.Rows.Add(1, "John Hammond")
dt.Rows.Add(2, "Mudassar Khan")
dt.Rows.Add(3, "Suzanne Mathews")
dt.Rows.Add(4, "Robert Schidner")
'Insert the Default Item to DataTable.
Dim row As DataRow = dt.NewRow
row(0) = 0
row(1) = "Please select"
dt.Rows.InsertAt(row, 0)
'Assign DataTable as DataSource.
cbCustomers.DataSource = dt
cbCustomers.DisplayMember = "Name"
cbCustomers.ValueMember = "Id"
End Sub
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim message As String = ("Name: " + cbCustomers.Text)
message = (message + Environment.NewLine)
message = (message + ("CustomerId: " + cbCustomers.SelectedValue))
MessageBox.Show(message)
End Sub
Screenshot