Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
2
Answers
How to fill DataGridView Cells on cellvaluechanged in MYSQL
Jim Tat
7y
223
1
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.
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#