【发布时间】:2014-01-18 01:56:29
【问题描述】:
我有 DataGridView(dgHome) 在 parentForm(Home) 中有一些列。 子 Form(bill) 有 DataGridView(dgbill) 。 我需要当我单击 dgHome 中的任何列时,它会将这些列添加到 dgbill。 我希望它很清楚。
`private void dgMenu_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
DataTable dt;
if (e.RowIndex > -1)
{
if (k < 4)
{
DataGridViewRow rw = this.dgMenu.Rows[e.RowIndex];
string t = rw.Cells[1].Value.ToString();
if (k == 1)
{
dt = f.SelectFoodType(t);
}
else if (k == 2)
{
dt = a.SelectAdditionType(t);
}
else if (k == 3)
{
dt = d.SelectDrinkType(t);
}
else
{
MessageBox.Show("select Food, Drink or Addition");
return;
}
dgMenu.DataSource = null;
dgMenu.DataSource = dt;
dgMenu.Columns[0].Visible = dgMenu.Columns[2].Visible = false;
dgMenu.Columns[1].HeaderText = t;
dgMenu.Columns[3].HeaderText = "Price";
k = 100;
}
else
{
DataGridViewRow rw = this.dgMenu.Rows[e.RowIndex];
string productname = rw.Cells[1].Value.ToString();
string price = rw.Cells[3].Value.ToString();
string input = Microsoft.VisualBasic.Interaction.InputBox("Enter Quantity: ", "Quantity", "1", -1, -1);
int q;
bool x = int.TryParse(input, out q);
if (x)
{
EnBill b = new EnBill(UserId);
if (IsFormOpen(typeof(EnBill)))
{
/* in this space I want to add this columns to another DataGridView in another Form*/
}
}
else
{
MessageBox.Show("No Input or Valid Input");
}
}
}
}`
【问题讨论】:
-
显示你尝试了什么以及你在哪里堆叠?
-
嗯...向我们展示一些爱...发布一些代码,并说明在哪里或什么对您不起作用。
-
对不起,我不能发布任何图片,我的代码很复杂
-
最后我添加了一个代码:D
标签: c# mysql sql database datagridview