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

AutoMapper for Nested inside Nested with Entity Framework?
What are the possible parameters for CompilerParameters.CompilerOptions
More than one instance of IsolatedStorageSettings?
Create Nest query with both HasChild and Query operators
Windows Phone 8 secondary tiles crash when not in Debug Mode
Cut off the end of a string
Generics in enum
How to Extract value of a cdata from xelement?
WinForms.Show() - “Error Creating Window Handle” - NOT using up handles
Why is SQL Server 2012 faster than MongoDB for this query [closed]
Reference could not be found
WCF data service client connect using session
Xna 4 Model Rotation with inertia not working as expected with variable updates
Best method to check if a point lies on an arc in c#
Remove ConnectionString from Web.config using Entity Framework CodeFirst
Resize parent by moving splitter

Categories

HOME
autohotkey
google-cloud-pubsub
oracle-sqldeveloper
compression
service
nagios
salesforce-lightning
xss
opengl-es
terminal
ms-access-2010
multipartform-data
atlassian-fisheye
markdown
ephesoft
cracking
runtime
ng2-charts
element
github-flavored-markdown
facebook-marketing-api
django-rest-auth
coccinelle
combinations
ecmascript-2017
grunt-contrib-uglify
expressionengine
windows-mobile
symlink
dynamic-memory-allocation
uibarbuttonitem
2checkout
textview
login-required
language-detection
jcr
microstrategy
offset
zimbra
minitest
ponylang
kepserverex
stencyl
jibx
lex
aura-framework
compiler-warnings
logan-square
infovis
appcmd
cancan
node-java
tsc
zsh-completion
rowname
normalisation
audiorecord
angular-i18n
instabug
ruby-1.8.7
bootstrap-tabs
hexagonal-tiles
callfire
tidesdk
genero
data-quality-services
illegalargumentexception
breeze-sharp
pnunit
switchpreference
cs193p
visual-studio-setup-proje
opencobol
farpoint-spread
image-preloader
randomaccessfile
ie-developer-tools
pechkin
ojb
android-library
jython-2.5
simplemembership
ntdll
libx264
jquery-1.8
erlide
optimistic-concurrency
mvcmailer
jqueryi-ui-buttonset
automapper-2
xpolog
symfony-1.2
meego-harmattan
http-response-codes
dongle
time-management
expander
cross-cutting-concerns
hotfix

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