J
John6272
Guest
Hi, i'm facing datagridview problem and also i google it but didn't found any working solution. Please help me in solving my problem.
i have DataGridView with below Column:
1st Column is "ComboBoxCell" Hearder "CategoryCode"
2nd Column is "ComboBoxCell" Hearder "ProductCode"
3rd Column is "TextBoxCell" Hearder "ProductName"
also i have a database(named:SSProducts) with two tables
1st table is Category(Columns: CategoryCode, CategoryName)
2nd table is Product(Columns: CategoryCode, ProductCode, ProductName)
when DataGridView form is open then the 1st column of DataGridView is fill with the value of DataBase Category table. for that i write the below code and the code is working correctly.
private void Category_Product_Load(object sender, EventArgs e)
{
fillcategorycombo();
}
private void fillcategorycombo()
{
try
{
//DataGridView 1st Column Name
ENPB_categorycode.Items.Clear();
using (SQLiteConnection conn = new SQLiteConnection(StockCategoriesComboFill.Conn()))
{
string CommandText = "SELECT CategoryCode FROM Category ORDER BY CategoryCode";
using (SQLiteCommand cmd = new SQLiteCommand(CommandText, conn))
{
conn.Open();
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
ENPB_categorycode.Items.Add(dr["CategoryCode"].ToString());
}
}
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
when form is load the 1st column of DataGridView is filled with database value correctly. My problem is that:
when the user select the CategoryCode from 1st DataGridView ComboBoxCell then the 2nd DataGridView ComboBoxCell filled with database 2nd table(Product) column(ProductCode).
i write below code to fill 2nd DataGridView ComboboxCell with database but i didn't know where i use it.
private void fillproductcombo()
{
try
{
ENPB_detail.Items.Clear();
if (ENPB_categorycode.Selected)
{
using (SQLiteConnection conn = new SQLiteConnection(StockProductsComboFill.Conn()))
{
string CommandText = "SELECT * FROM Product WHERE [CategoryCode]=@id";
using (SQLiteCommand cmd = new SQLiteCommand(CommandText, conn))
{
cmd.Parameters.AddWithValue("@id", ENPB_categorycode.Selected.ToString());
conn.Open();
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
ENPB_detail.Items.Add(dr["ProductName"].ToString());
}
}
}
}
else
{
XtraMessageBox.Show("Please Select the Category Code From the List", "Category isn't Selected", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Tell me where i use this code to fill my second DataGridView comboboxcell. In combobox there is a event called SelectedChangeIndex, but DataGridView comboboxcell have no such event.
Help me how can i do that, also i want to that when user select 2nd comboboxcell value then show the name of that value in 3rd column of DataGridView.
waiting for help...
Continue reading...
i have DataGridView with below Column:
1st Column is "ComboBoxCell" Hearder "CategoryCode"
2nd Column is "ComboBoxCell" Hearder "ProductCode"
3rd Column is "TextBoxCell" Hearder "ProductName"
also i have a database(named:SSProducts) with two tables
1st table is Category(Columns: CategoryCode, CategoryName)
2nd table is Product(Columns: CategoryCode, ProductCode, ProductName)
when DataGridView form is open then the 1st column of DataGridView is fill with the value of DataBase Category table. for that i write the below code and the code is working correctly.
private void Category_Product_Load(object sender, EventArgs e)
{
fillcategorycombo();
}
private void fillcategorycombo()
{
try
{
//DataGridView 1st Column Name
ENPB_categorycode.Items.Clear();
using (SQLiteConnection conn = new SQLiteConnection(StockCategoriesComboFill.Conn()))
{
string CommandText = "SELECT CategoryCode FROM Category ORDER BY CategoryCode";
using (SQLiteCommand cmd = new SQLiteCommand(CommandText, conn))
{
conn.Open();
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
ENPB_categorycode.Items.Add(dr["CategoryCode"].ToString());
}
}
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
when form is load the 1st column of DataGridView is filled with database value correctly. My problem is that:
when the user select the CategoryCode from 1st DataGridView ComboBoxCell then the 2nd DataGridView ComboBoxCell filled with database 2nd table(Product) column(ProductCode).
i write below code to fill 2nd DataGridView ComboboxCell with database but i didn't know where i use it.
private void fillproductcombo()
{
try
{
ENPB_detail.Items.Clear();
if (ENPB_categorycode.Selected)
{
using (SQLiteConnection conn = new SQLiteConnection(StockProductsComboFill.Conn()))
{
string CommandText = "SELECT * FROM Product WHERE [CategoryCode]=@id";
using (SQLiteCommand cmd = new SQLiteCommand(CommandText, conn))
{
cmd.Parameters.AddWithValue("@id", ENPB_categorycode.Selected.ToString());
conn.Open();
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
ENPB_detail.Items.Add(dr["ProductName"].ToString());
}
}
}
}
else
{
XtraMessageBox.Show("Please Select the Category Code From the List", "Category isn't Selected", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Tell me where i use this code to fill my second DataGridView comboboxcell. In combobox there is a event called SelectedChangeIndex, but DataGridView comboboxcell have no such event.
Help me how can i do that, also i want to that when user select 2nd comboboxcell value then show the name of that value in 3rd column of DataGridView.
waiting for help...
Continue reading...