473,326 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

how to add a button in datagridview in vb.net

24
as asked in the title. how to add button to the datagridview in vb.net. to control the actions such as delete one row.
PS:the button are expected to appear at the end of each row.
PS:I use dataset to specify the datasource of datagridview in code.
Sep 15 '08 #1
5 45053
MrMancunian
569 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. Dim buttonColumn As New DataGridViewButtonColumn
  2. buttonColumn.Name = "Button"
  3. DataGridView1.Columns.Add(buttonColumn)
Sep 15 '08 #2
lucoin
24
Expand|Select|Wrap|Line Numbers
  1. Dim buttonColumn As New DataGridViewButtonColumn
  2. buttonColumn.Name = "Button"
  3. DataGridView1.Columns.Add(buttonColumn)
Thank you. It works. but how to add click event to the button to monitor the changes to a special cell in the certain row.
Sep 16 '08 #3
MrMancunian
569 Expert 512MB
Thank you. It works. but how to add click event to the button to monitor the changes to a special cell in the certain row.
In my opinion, the best way to do this is using the System.Windows.Forms.DataGridViewCellEventArgs. It is saved in 'e' as shown in the line of code beneath:

Expand|Select|Wrap|Line Numbers
  1. Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
You make sure that you know the name of the column the button is in and then you query the 'e' for the columnindex. After that, you track which row is clicked by using 'e' for the rowindex. Something like this:

Expand|Select|Wrap|Line Numbers
  1. Dim gr As New DataGridView
  2. gr = sender
  3.   Select Case e.ColumnIndex
  4.     Case Is > -1
  5.       Select Case gr.Columns(e.ColumnIndex).Name
  6.         Case "Button"
  7.           return gr.Rows(e.RowIndex).......etc.
  8.  
Sep 16 '08 #4
lucoin
24
Expand|Select|Wrap|Line Numbers
  1. Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
[/code]
Cool,everything works.
as the same I add imagecolumn to the the datagridview. but how to add pics to the buttom. because in my database I save the photo column as relative path in the program folder. how can I reference the path and review the pics on on the imagesbutton.

thanks a lot
Sep 17 '08 #5
lucoin
24
I fond some codes can add images to the column
just like to set the image cells value through a shared method image.fromfile("<ralative path here>")
hope this helps others
Sep 17 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mark Carew | last post by:
Hi, I'm writing a winform app (as practice) that has as one of its features a button that reads an xml file to a datagridview. No matter what I do I get two columns instead of one. The...
11
by: Kevin | last post by:
I've been searching forever for examples of saving data changes in a DataGridView. There's all kinds of examples, but none really show how to save changes. Someone please help me. I have a...
1
by: jjmurali | last post by:
hi guys i have one problem with datagridview.. i m displaying data in datagridview in c# application. i added one checkbox column to datagridview ..as well as i have one button(Select All),...
2
by: snowdog17 | last post by:
Hello, I am a student and I need help with my VB task. I am currently using VB 2005 Express and I am fairly new to it, although I have programed in Delphi before....
0
by: Przemek | last post by:
Hello, I have a little problem. I use flat style for Buttons on DataGridView and every looks fine (non 3d buttons) but when I move mouse over DataGridView Button then background of this button...
1
nev
by: nev | last post by:
Happy Easter to all! I have a problem with a datagridview. I placed code in a button click event as follows: dim dtt as datatable = dataset.employees.copy dtt.DefaultView.RowFilter = "='" &...
1
by: mtembene | last post by:
I have a windows form "BaseForm" that contains a DataGridView that is not bound to any datasources and a button. Both of these controls have a modifier of "Protected Internal" and none of the...
6
by: Miro | last post by:
Sorry for the cross post. I am stuck. I have a datagridview for poker rounds. Basically there are 3 columns in this datagridview. "Round" "SmallBlind" "BigBlind" I have an issue when I tab...
1
by: Limno | last post by:
Can anyone suggest me how to pass datagridview data to database. Process must be like this, if the user enter multiple data into the datagridview after user press "save" button, datagridview data...
1
by: Avedo | last post by:
Hello! I have a form application with a DataGridView, and an Save/Delete and Cancel button. When the application is opened, it is supplied an XML file that may or may not exist, and display the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.