Tech
Forums
Jobs
Books
Events
Live
Interviews Prep
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
How to fill DataGridView Cells on cellvaluechanged in MYSQL
Jim Tat
Apr 29 2017 5:31 AM
207
Reply
I have a DataGridView in which there are 4 columns; Reference,Quantity, Rate and Amount.
The DataGridView is Editable. When I enter a value in the Reference Column then immediately it will fill the other values in the others cells from mysql database.
This is what I tried....
private
void
TAB_Credit_CellValueChanged(
object
sender, DataGridViewCellEventArgs e)
{
try
{
if
(TAB_Credit.CurrentCell.ColumnIndex == 0)
{
MySqlDataAdapter sa =
new
MySqlDataAdapter(
"SELECT * FROM table WHERE Reference='"
+ TAB_Credit.Rows[e.RowIndex].Cells[
"Reference"
].Value +
"'"
, MyConnexion);
DataTable dt2 =
new
DataTable();
sa.Fill(dt2);
double
value = (
double
)TAB_Credit.Rows[e.RowIndex].Cells[
"Quantite"
].Value * (
double
)TAB_Credit.Rows[e.RowIndex].Cells[
"PU"
].Value;
TAB_Credit.Rows[e.RowIndex].Cells[
"Designation"
].Value = dt2.Rows[0][
"Designation"
].ToString();
TAB_Credit.Rows[e.RowIndex].Cells[
"Quantite"
].Value = dt2.Rows[0][
"Quantite"
].ToString();
TAB_Credit.Rows[e.RowIndex].Cells[
"PU"
].Value = dt2.Rows[0][
"Prix_Unitaire"
].ToString();
TAB_Credit.Rows[e.RowIndex].Cells[
"Total"
].Value = value.ToString();
}
}
catch
{ }
}
So in the datagrid, when I insert in the Reference Cell nothing is appearing in the other cells.
Thank you.
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
Best way to read from Datatable and return JsonResult IN MVC
Filling datagridview cells after validating first row in C#