How display images in datagridview? c#
I am developing an application in C # for desktop using Visual Studio Express 2010.
I have a table in MySQL called Products with 3 fields:
ID -> Product_Name -> product_image
The field product_Image
stores the image path in my hard drive (not the image itself)
An example of a record would be:
0001 --- Mousepad XYZ ---- c:imagesmousepad.jpg
I wonder how fill a datagridview
that shows the ID, Produt name, and - especially - the product image
for each record in my SQL query.
All the examples I found were used manual data inserts, but I am looking for an example to fill the datagridview with data from a SQL query, not a manual insertion.
Edit:
Thank you for help, but could not directly apply the solutions.
I already have a datagridview on my form, I have no need to create in runtime.
I need something like that (I'll write a generic way)
returnMySQL = "select * from products";
while (returnMySQL)
{
fill datagrid with ID, product name, product image
}
c# database winforms datagrid datagridview
add a comment |
I am developing an application in C # for desktop using Visual Studio Express 2010.
I have a table in MySQL called Products with 3 fields:
ID -> Product_Name -> product_image
The field product_Image
stores the image path in my hard drive (not the image itself)
An example of a record would be:
0001 --- Mousepad XYZ ---- c:imagesmousepad.jpg
I wonder how fill a datagridview
that shows the ID, Produt name, and - especially - the product image
for each record in my SQL query.
All the examples I found were used manual data inserts, but I am looking for an example to fill the datagridview with data from a SQL query, not a manual insertion.
Edit:
Thank you for help, but could not directly apply the solutions.
I already have a datagridview on my form, I have no need to create in runtime.
I need something like that (I'll write a generic way)
returnMySQL = "select * from products";
while (returnMySQL)
{
fill datagrid with ID, product name, product image
}
c# database winforms datagrid datagridview
Do you have all 3 three values in one attribute?
– Shaharyar
May 28 '13 at 5:29
you need to store the image path indatabase
and need to storeimage
itself into a folder in your project and just apply a select query and bind yourdatagridview
with normal query,
– Rahul
May 28 '13 at 5:30
add a comment |
I am developing an application in C # for desktop using Visual Studio Express 2010.
I have a table in MySQL called Products with 3 fields:
ID -> Product_Name -> product_image
The field product_Image
stores the image path in my hard drive (not the image itself)
An example of a record would be:
0001 --- Mousepad XYZ ---- c:imagesmousepad.jpg
I wonder how fill a datagridview
that shows the ID, Produt name, and - especially - the product image
for each record in my SQL query.
All the examples I found were used manual data inserts, but I am looking for an example to fill the datagridview with data from a SQL query, not a manual insertion.
Edit:
Thank you for help, but could not directly apply the solutions.
I already have a datagridview on my form, I have no need to create in runtime.
I need something like that (I'll write a generic way)
returnMySQL = "select * from products";
while (returnMySQL)
{
fill datagrid with ID, product name, product image
}
c# database winforms datagrid datagridview
I am developing an application in C # for desktop using Visual Studio Express 2010.
I have a table in MySQL called Products with 3 fields:
ID -> Product_Name -> product_image
The field product_Image
stores the image path in my hard drive (not the image itself)
An example of a record would be:
0001 --- Mousepad XYZ ---- c:imagesmousepad.jpg
I wonder how fill a datagridview
that shows the ID, Produt name, and - especially - the product image
for each record in my SQL query.
All the examples I found were used manual data inserts, but I am looking for an example to fill the datagridview with data from a SQL query, not a manual insertion.
Edit:
Thank you for help, but could not directly apply the solutions.
I already have a datagridview on my form, I have no need to create in runtime.
I need something like that (I'll write a generic way)
returnMySQL = "select * from products";
while (returnMySQL)
{
fill datagrid with ID, product name, product image
}
c# database winforms datagrid datagridview
c# database winforms datagrid datagridview
edited May 28 '13 at 6:10
Reboot
asked May 28 '13 at 5:24
RebootReboot
23116
23116
Do you have all 3 three values in one attribute?
– Shaharyar
May 28 '13 at 5:29
you need to store the image path indatabase
and need to storeimage
itself into a folder in your project and just apply a select query and bind yourdatagridview
with normal query,
– Rahul
May 28 '13 at 5:30
add a comment |
Do you have all 3 three values in one attribute?
– Shaharyar
May 28 '13 at 5:29
you need to store the image path indatabase
and need to storeimage
itself into a folder in your project and just apply a select query and bind yourdatagridview
with normal query,
– Rahul
May 28 '13 at 5:30
Do you have all 3 three values in one attribute?
– Shaharyar
May 28 '13 at 5:29
Do you have all 3 three values in one attribute?
– Shaharyar
May 28 '13 at 5:29
you need to store the image path in
database
and need to store image
itself into a folder in your project and just apply a select query and bind your datagridview
with normal query,– Rahul
May 28 '13 at 5:30
you need to store the image path in
database
and need to store image
itself into a folder in your project and just apply a select query and bind your datagridview
with normal query,– Rahul
May 28 '13 at 5:30
add a comment |
3 Answers
3
active
oldest
votes
Use following Code:
Bitmap img;
img = new Bitmap(@"c:imagesmousepad.jpg");
// Create the DGV with an Image column
DataGridView dgv = new DataGridView();
this.Controls.Add(dgv);
DataGridViewImageColumn imageCol = new DataGridViewImageColumn();
dgv.Columns.Add(imageCol);
// Add a row and set its value to the image
dgv.Rows.Add();
dgv.Rows[0].Cells[0].Value = img;
Referance LINK .
I guess this is winform coz ofdesktop
tag
– V4Vendetta
May 28 '13 at 5:36
coze ofdatagridview
notgridview
– Ria
May 28 '13 at 5:38
@Ria sorry, i edited it.
– Freelancer
May 28 '13 at 5:39
@V4Vendetta thanks for pointing it out.
– Freelancer
May 28 '13 at 5:39
add a comment |
You can add images with the following way:
//you need to perform some parsing to retrieve individual values of ID, Name and ImagePath
string path = @"c:imagesmousepad.jpg";
string ID = "0001";
string Product_Name = "Mousepad XYZ";
dataGridView1.Rows.Add(ID, Product_Name, Bitmap.FromFile(path));
add a comment |
You can Doing this simple way
SqlConnection conn=New SqlConnection("SERVER=127.0.0.1;DATABASE=bdss;UID=sa;PASSWORD=1234");
SqlDataAdapter adpt = new SqlDataAdapter("select * from products",conn);
DataTable dt = new System.Data.DataTable();
adpt.Fill(dt);
int count = dt.Rows.Count;
dataGridView1.DataSource = dt;
thats All you can change Datagrid view height and with according your requirment
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16784440%2fhow-display-images-in-datagridview-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use following Code:
Bitmap img;
img = new Bitmap(@"c:imagesmousepad.jpg");
// Create the DGV with an Image column
DataGridView dgv = new DataGridView();
this.Controls.Add(dgv);
DataGridViewImageColumn imageCol = new DataGridViewImageColumn();
dgv.Columns.Add(imageCol);
// Add a row and set its value to the image
dgv.Rows.Add();
dgv.Rows[0].Cells[0].Value = img;
Referance LINK .
I guess this is winform coz ofdesktop
tag
– V4Vendetta
May 28 '13 at 5:36
coze ofdatagridview
notgridview
– Ria
May 28 '13 at 5:38
@Ria sorry, i edited it.
– Freelancer
May 28 '13 at 5:39
@V4Vendetta thanks for pointing it out.
– Freelancer
May 28 '13 at 5:39
add a comment |
Use following Code:
Bitmap img;
img = new Bitmap(@"c:imagesmousepad.jpg");
// Create the DGV with an Image column
DataGridView dgv = new DataGridView();
this.Controls.Add(dgv);
DataGridViewImageColumn imageCol = new DataGridViewImageColumn();
dgv.Columns.Add(imageCol);
// Add a row and set its value to the image
dgv.Rows.Add();
dgv.Rows[0].Cells[0].Value = img;
Referance LINK .
I guess this is winform coz ofdesktop
tag
– V4Vendetta
May 28 '13 at 5:36
coze ofdatagridview
notgridview
– Ria
May 28 '13 at 5:38
@Ria sorry, i edited it.
– Freelancer
May 28 '13 at 5:39
@V4Vendetta thanks for pointing it out.
– Freelancer
May 28 '13 at 5:39
add a comment |
Use following Code:
Bitmap img;
img = new Bitmap(@"c:imagesmousepad.jpg");
// Create the DGV with an Image column
DataGridView dgv = new DataGridView();
this.Controls.Add(dgv);
DataGridViewImageColumn imageCol = new DataGridViewImageColumn();
dgv.Columns.Add(imageCol);
// Add a row and set its value to the image
dgv.Rows.Add();
dgv.Rows[0].Cells[0].Value = img;
Referance LINK .
Use following Code:
Bitmap img;
img = new Bitmap(@"c:imagesmousepad.jpg");
// Create the DGV with an Image column
DataGridView dgv = new DataGridView();
this.Controls.Add(dgv);
DataGridViewImageColumn imageCol = new DataGridViewImageColumn();
dgv.Columns.Add(imageCol);
// Add a row and set its value to the image
dgv.Rows.Add();
dgv.Rows[0].Cells[0].Value = img;
Referance LINK .
edited May 28 '13 at 5:40
answered May 28 '13 at 5:34
FreelancerFreelancer
7,72873273
7,72873273
I guess this is winform coz ofdesktop
tag
– V4Vendetta
May 28 '13 at 5:36
coze ofdatagridview
notgridview
– Ria
May 28 '13 at 5:38
@Ria sorry, i edited it.
– Freelancer
May 28 '13 at 5:39
@V4Vendetta thanks for pointing it out.
– Freelancer
May 28 '13 at 5:39
add a comment |
I guess this is winform coz ofdesktop
tag
– V4Vendetta
May 28 '13 at 5:36
coze ofdatagridview
notgridview
– Ria
May 28 '13 at 5:38
@Ria sorry, i edited it.
– Freelancer
May 28 '13 at 5:39
@V4Vendetta thanks for pointing it out.
– Freelancer
May 28 '13 at 5:39
I guess this is winform coz of
desktop
tag– V4Vendetta
May 28 '13 at 5:36
I guess this is winform coz of
desktop
tag– V4Vendetta
May 28 '13 at 5:36
coze of
datagridview
not gridview
– Ria
May 28 '13 at 5:38
coze of
datagridview
not gridview
– Ria
May 28 '13 at 5:38
@Ria sorry, i edited it.
– Freelancer
May 28 '13 at 5:39
@Ria sorry, i edited it.
– Freelancer
May 28 '13 at 5:39
@V4Vendetta thanks for pointing it out.
– Freelancer
May 28 '13 at 5:39
@V4Vendetta thanks for pointing it out.
– Freelancer
May 28 '13 at 5:39
add a comment |
You can add images with the following way:
//you need to perform some parsing to retrieve individual values of ID, Name and ImagePath
string path = @"c:imagesmousepad.jpg";
string ID = "0001";
string Product_Name = "Mousepad XYZ";
dataGridView1.Rows.Add(ID, Product_Name, Bitmap.FromFile(path));
add a comment |
You can add images with the following way:
//you need to perform some parsing to retrieve individual values of ID, Name and ImagePath
string path = @"c:imagesmousepad.jpg";
string ID = "0001";
string Product_Name = "Mousepad XYZ";
dataGridView1.Rows.Add(ID, Product_Name, Bitmap.FromFile(path));
add a comment |
You can add images with the following way:
//you need to perform some parsing to retrieve individual values of ID, Name and ImagePath
string path = @"c:imagesmousepad.jpg";
string ID = "0001";
string Product_Name = "Mousepad XYZ";
dataGridView1.Rows.Add(ID, Product_Name, Bitmap.FromFile(path));
You can add images with the following way:
//you need to perform some parsing to retrieve individual values of ID, Name and ImagePath
string path = @"c:imagesmousepad.jpg";
string ID = "0001";
string Product_Name = "Mousepad XYZ";
dataGridView1.Rows.Add(ID, Product_Name, Bitmap.FromFile(path));
answered May 28 '13 at 5:43
ShaharyarShaharyar
9,88622949
9,88622949
add a comment |
add a comment |
You can Doing this simple way
SqlConnection conn=New SqlConnection("SERVER=127.0.0.1;DATABASE=bdss;UID=sa;PASSWORD=1234");
SqlDataAdapter adpt = new SqlDataAdapter("select * from products",conn);
DataTable dt = new System.Data.DataTable();
adpt.Fill(dt);
int count = dt.Rows.Count;
dataGridView1.DataSource = dt;
thats All you can change Datagrid view height and with according your requirment
add a comment |
You can Doing this simple way
SqlConnection conn=New SqlConnection("SERVER=127.0.0.1;DATABASE=bdss;UID=sa;PASSWORD=1234");
SqlDataAdapter adpt = new SqlDataAdapter("select * from products",conn);
DataTable dt = new System.Data.DataTable();
adpt.Fill(dt);
int count = dt.Rows.Count;
dataGridView1.DataSource = dt;
thats All you can change Datagrid view height and with according your requirment
add a comment |
You can Doing this simple way
SqlConnection conn=New SqlConnection("SERVER=127.0.0.1;DATABASE=bdss;UID=sa;PASSWORD=1234");
SqlDataAdapter adpt = new SqlDataAdapter("select * from products",conn);
DataTable dt = new System.Data.DataTable();
adpt.Fill(dt);
int count = dt.Rows.Count;
dataGridView1.DataSource = dt;
thats All you can change Datagrid view height and with according your requirment
You can Doing this simple way
SqlConnection conn=New SqlConnection("SERVER=127.0.0.1;DATABASE=bdss;UID=sa;PASSWORD=1234");
SqlDataAdapter adpt = new SqlDataAdapter("select * from products",conn);
DataTable dt = new System.Data.DataTable();
adpt.Fill(dt);
int count = dt.Rows.Count;
dataGridView1.DataSource = dt;
thats All you can change Datagrid view height and with according your requirment
answered Mar 22 '17 at 10:58
Gayan Chinthaka DharmarathnaGayan Chinthaka Dharmarathna
95116
95116
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16784440%2fhow-display-images-in-datagridview-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do you have all 3 three values in one attribute?
– Shaharyar
May 28 '13 at 5:29
you need to store the image path in
database
and need to storeimage
itself into a folder in your project and just apply a select query and bind yourdatagridview
with normal query,– Rahul
May 28 '13 at 5:30