0

i am working on vb.net windows application.i have a grid view ..i am populating my data grid view like this:

in load event i wrote code 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 as Image 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

so my grid view like this:enter image description here

i want to add button in my image column..so i try code like this: but that is adding one more column.

 Dim btn As New DataGridViewButtonColumn
        gv.Columns.Insert(6, btn).  

so how i can add button in my image column

3 Answers 3

5

You need to set the button name to this to work like so :

Dim btn As New DataGridViewButtonColumn
btn.HeaderText = "Click Data"
btn.Text = "Click Here"
btn.Name = "btn"
btn.UseColumnTextForButtonValue = True
gv.Columns.Insert(6, btn)
Sign up to request clarification or add additional context in comments.

6 Comments

this time adding new column..sir i dont want to add new column
i want to get button in image column
you can't insert button type cell on normal column it must be button column.
so i cant add button in my image column??
is there any way to declare that column is Buttoncolumn type?
|
0

Try this code for displaying the DataGridView:

Dim btn As New DataGridViewButtonColumn()
        DataGridView1.Columns.Add(btn)
        btn.HeaderText = "Click Data"
        btn.Text = "Click Here"
        btn.Name = "btn"
        btn.UseColumnTextForButtonValue = True

Comments

0
For Each row As DataGridViewRow In FilterDataDatagridview.Rows
                Dim btn As DataGridViewButtonColumn = DataDatagridview1.Columns("Image")
                btn.HeaderText = "Click Data"
                btn.Text = "Click Here"
                btn.Name = "btn"
                btn.UseColumnTextForButtonValue = True
            Next
''''''''''''you will have converted the datagridviewcolumn 'Image' to button
''''''''''''you will click the image at the center for it to work

2 Comments

Please avoid code only answer, and add some explanation. Especially when answering to old questions, it is important to explain why your answer is different, and even better than existing answers.
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.