{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new mridulForm());
}
}
}
place a gridview control(dataGridView1) in form first.In form code behind file,
the codes are as follows.Also place two button and its click events shown in code below -
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SimpleGridView
{
public partial class mridulForm : Form
{
enum productType { MilkTea, LemonTea, Coffe }
public mridulForm()
{
InitializeComponent();
}
private void saveButton_Click(object sender, EventArgs e)
{
int price = 0;
productType Obj = (productType)Enum.Parse(typeof(productType),
itemComboBox.Text.ToString());
if (productType.MilkTea == Obj)
{ price = 5; }
else if (productType.LemonTea == Obj)
{ price = 3; }
else if (productType.Coffe == Obj)
{ price = 8; }
dataGridView1.Rows[0].Cells[0].Value = itemComboBox.Text;
dataGridView1.Rows[0].Cells[1].Value =
price * Convert.ToInt16(itemPriceTextBox.Text);
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
} }