c#


How do I add button in each row of column of already bound datagridview in Windows application?


I want to add a button to each row of a column of an already bounded datagridview, and add an event to it (in VS 2005, Windows application).
I have searched a lot but was unable to find a working solution.
before binding to the datasource set :
grd.AutoGenerateColumns = false;
create yourself all DataGridView columns and bind them to the datasource:
DataGridViewTextBoxColumn dgvc = new DataGridViewTextBoxColumn();
dgvc.HeaderText = "column_header";
dgvc.DataPropertyName = "column_name";
create a DataGridViewButtonColumn.
DataGridViewButtonColumn dgvbt = new DataGridViewButtonColumn();
If you want this column not bound, set header text, the same text on all buttons:
dgvbt.HeaderText = "OK?";
dgvbt.Text = "ok"; // works also when bound
dgvbt.UseColumnTextForButtonValue = true; //
If you want your column to be also bounded and each button have the text of underlying cell, bind it:
dgvbt.DataPropertyName = "column_bt";
Add created columns to the DataGridView:
grd.Columns.Add(dgvc);
grd.Columns.Add(dgvbt);
handle the CellClick event of the DataGridView:
grd.CellClick += new DataGridViewCellEventHandler(grd_CellClick);
void grd_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex == index_of_button_column)
{
MessageBox.Show(this, e.RowIndex.ToString() + " Clicked!");
//...
}
}
for more, see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewbuttoncolumn.aspx

Related Links

C# Service Reference error: A child element named 'element' with same key already exists
How to remove broken background of ListViewItem In UWP?
SelectIndexChange code behind from a different nameSpace
C#: Optimize conditional within a loop
Post JSON object array to a Web API
Bind to concatenated text
C# Interop, how to get the max length within a range of cells in Excel
Send list of objects with different classes derived from same parent in a WCF service
Using functions from a different class Visual Studio c# [closed]
Get element of an enum by sending XmlEnumAttribute c#?
I keep getting this error in while using ASP.NET Core
Wait for process to show up
Change Proxy at runtime in Selenium.Webdriver + PhantomJS using C#
Microsoft Dynamics Nav Post using Web Services
How do I modify my web.config file to support SQL Server 2016?
Web Api project with another data project both have entity framework only wanting connection string in data project

Categories

HOME
gulp
system-calls
service
weblogic
intellisense
ibm
latex
django-middleware
lithium
sms
opengl-es
snmp
docker-compose
android-webview
phpexcel
spring-data-solr
yui
github-flavored-markdown
luis
nsoperation
conditional-formatting
minimagick
multipart
aws-iot
devexpress-mvc
quality-center
handle
ps
continuous-fourier
orgchart
libxml2
marionette
csproj
scene7
node-soap
webmock
zimbra
tunnel
ansible-inventory
rythm
scip
anypoint-studio
tapply
vertical-alignment
peerjs
nshttpurlresponse
ocpjp
nao-robot
openxava
google-cloud-shell
runtime-permissions
perldoc
openpgp.js
totalview
access-violation
deck.js
scriptengine
sprockets
weblogic-maven-plugin
abstract
overlapping
mojolicious
gulp-cdnizer
transport
windows-phone-8-emulator
om
roslyn-code-analysis
log-analysis
sicstus-prolog
screen-lock
firebase-tools
cl.exe
quickfixn
vundle
parsefloat
step
mvcgrid
nspopupbutton
django-tests
kuka-krl
boofcv
proj4
exi
codeigniter-form-helper
pudb
brew
zepto
linear-interpolation
netzke
derived-class
certificate-revocation
socketasynceventargs
pex-and-moles
gmagick
functional-specifications
miniport
numerical-computing
focus-stealing
zend-acl
disk-based

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App