How to create ItemData in C Sharp

In this article i will explain how to create ItemData. You need to create new project and name of the project is ItemDatainCSharp and add combobox control then create custom class or structure and bind to the combobox control.

Create Class and give the name of class is ItemData and copy this code and paste


please give your comments


// Custom Structure or Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ItemDatainCSharp
{
    public struct ItemData
    {
        public intID;
        public stringEmpName;
        public ItemData(int_ID, string _EMName)
        {
            ID = _ID;
            EmpName = _EMName;
        }
        public overridestring  ToString()
        {
         return this.EmpName;
        }
       
    }
}
Open the form view code and Copy this code and paste.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ItemDatainCSharp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private voidForm1_Load(object sender, EventArgs e)
        {
            comboBox1.Items.Clear();
            comboBox1.Items.Add(new ItemData(101,“John”));
            comboBox1.Items.Add(new ItemData(102, “Ajay”));
        }
        private voidcomboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            MessageBox.Show(“Employee ID : “ + ((ItemData)comboBox1.SelectedItem).ID  + Environment.NewLine +
                “Employee Name : “ + ((ItemData)comboBox1.SelectedItem).EmpName.ToString());
        }
    }
}


One Comment on “How to create ItemData in C Sharp”

  1. Programming is very interesting and creative thing if you do it with love. Your blog code helps a lot to beginners to learn programming from basic to advance level. I really love this blog because I learn a lot from here and this process is still continuing.
    Love from Pro Programmer

Leave a Reply

Your email address will not be published. Required fields are marked *