0
votes

I am working on vb.net windows application..i am populating my data grid view using data source..I wrote code in my load event like this:

Dim cd As SqlCommandBuilder = New SqlCommandBuilder(adapter)
        adapter = New SqlDataAdapter("select c.cid,c.CompanyName,d.dtId,d.dtName as 
Department,d.dtPhone as Phone,d.dtEmail as Email,d.empimage from CompanyMaster_tbl c 
join  DepartmentMaster_tbl d on c.Cid=d.cId order by cid", con.connect)
        dt1 = New DataTable
        bSource = New BindingSource
        adapter.Fill(dt1) 'Filling dt with the information from the DB
        bSource.DataSource = dt1
        gv.DataSource = bSource
        gv.Columns("cid").Visible = False
        gv.Columns("dtId").Visible = False
  Dim img As New DataGridViewImageColumn
        img.HeaderText = "image"
        gv.Columns.Insert(6, img)

now my gridview showing like this: enter image description here

i want to show my image in my **image** column it self..how i can do that?

1
If you already bind datasource with gridview and it will showing image then why you want to add another column. If you want to change header text then change through code. gv.Columns("empimage").HeaderText = "image"Sameer
sir i dont want to add another column..i want to get my image in 'image' column..i meant need to get image in 4th columnuser3106114
img.DataPropertyName = "[PropertyName]";Sameer

1 Answers

1
votes

After assigning the datasource your adding the column "gv.Columns.Insert(6, img)". For this column data is not there. You need to add the images manually to this column.

for(int i = 0; i < gv.Rows.Count; i++)
{
    gv.Rows[i]["image"] =  gv.Rows[i]["empimage"];
}