Hours Combobox
In design page in the hours i have 5. when i click that hours 5 that hours should be displayed in the textbox.
Output i want as follows;
Hours 5 (combo box)
Textbox
when i click 5, that 5 is to be displayed in the textbox.
Then i have one button. when i click that button, that 5 displayed in the textbox should be shown in display in datagrdiview as follows;
in datagridview as follows;
Days
1
2
3
4
5
Alok UniyalPosted Mar 9, 2013, 2:57 AM
private void button1_Click(object sender, EventArgs e)
for(int i=0;i
DataGridViewRow row = new DataGridViewRow();
DataGridViewTextBoxCell cell1=new DataGridViewTextBoxCell();
cell1.Value=i+1;
row.Cells.Add(cell1);
dataGridView1.Rows.Add(row);
}
Satyapriya NayakPosted Mar 9, 2013, 2:44 AM
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Combo_textbox_datagridview
{
public partial class Form1 : Form
{
DataTable dt = new DataTable();
DataRow dr;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dt.Columns.Add("Days");
comboBox1.Text = "Select";
comboBox1.Items.Add("1");
comboBox1.Items.Add("2");
comboBox1.Items.Add("3");
comboBox1.Items.Add("4");
comboBox1.Items.Add("5");
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = comboBox1.SelectedItem.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
dr = dt.NewRow();
dr["Days"] = textBox1.Text;
dt.Rows.Add(dr);
dataGridView1.DataSource = dt;
}
}
}