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

google maps javascript api - get location on click
Xml Serialize List of Descendants
Replace “:” symbol (colon) by a space
Change Size of Jpeg File in C#
Why I got an error in the system when I use MIN in the SQL Query?
Why is there no int overload for SqlFunctions.StringConvert
Modify css file (minify) using HttpModule: GZip CRC check fails
How can I implement lazy bitmap loading?
Clicking js generated links in webbrowser control (C#)
Where to move constructing of disposable dependencies to improve testability?
eventaggregator vs services
How to get the printer status in WPF?
C# interface and generic combination. Want to return <T> instead of its base interface
What's the best way for a C# Desktop client to connect to a remote MySQL Db?
How to check that Request.QueryString has a specific value or not in ASP.NET?
Reporting Services Web Service, C# .NET code reuse

Categories

HOME
internet-explorer
skype-for-business
msbuild
google-cloud-pubsub
macros
teradata
compression
ebay-api
singleton
google-docs-api
sugarcrm
collision-detection
hibernate-mapping
rtc
suitecrm
vichuploaderbundle
android-actionbar
wallet
glibc
datasource
ajaxcontroltoolkit
rndis
ng-tags-input
suitescript
orgchart
typeclass
units-of-measurement
ilog
voyager
kofax
latency
armadillo
aspnetboilerplate
f#-fake
azure-data-catalog
npoco
infovis
activeandroid
bioperl
r-commander
spring-cloud-aws
disassembly
nls
glade
cosign-api
instaparse
bbedit
periodic-processing
web-performance
app-data
jcomponent
database-project
adempiere
musicbrainz
jsoncpp
polarion
litedb
esb-toolkit-2.1
tidesdk
radgrid
ultraedit
veeam
cordova-3
kss
information-hiding
lwuit
selenium-grid2
angular-file-upload
farpoint-spread
node-mongodb-native
acrofields
ekevent
svg-android
google-mirror-api
google-oauth-java-client
grape-api
tlbimp
azure-scheduler
servicemanager
phone-state-listener
antixsslibrary
feincms
rfc822
big-endian
xcode4.6.3
nserror
wxperl
advanceddatagrid
httppostedfilebase
jqtransform
nbehave
arraycollection
helios
dojox.gfx
unauthorized
memory-consumption

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