Fill datagridview with text from a combobox C#

  • Thread starter Thread starter Chris.ry
  • Start date Start date
C

Chris.ry

Guest
Hi i have a combobox(used as a list of all my products) that has something like this Drink Water 1 (for category name and price) loaded from a text file ,so far i can place the columns but can only add one product ,after adding another with a button the previous gets replaced.


private void button2_Click(object sender, EventArgs e)
{

DataTable dt = new DataTable();

{

dt.Columns.Add("Category");
dt.Columns.Add("Name");
dt.Columns.Add("Price");
}
string newline;
newline = comboBox1.Text;
DataRow dr = dt.NewRow();
string[] values = newline.Split( );
for (int i = 0; i < values.Length; i++)
{
dr = values;
}
dt.Rows.Add(dr);
dataGridView1.DataSource = dt;

}

Continue reading...
 
Back
Top