Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Button Column in windows form Datagrid .net1.1 framework
 

Button Column in windows form Datagrid .net1.1 framework

Hi ,
I need to develop a windows application using .net 1.1.
In some form i want Datagrid with button column for each row on click of each button i want to delete that particular row.
Can any please help me on doing it.

Note: Client requirments .net 1.1 (Vs2003)
veerabramhendra  Wednesday, September 16, 2009 2:59 PM

Hi veerabramhendra,

We need to create our own DataGridColumnStyle to handle the button column. The article below shows how to create a DataGridButtonColumn:
http://msdn.microsoft.com/en-us/library/ms996453.aspx#datagridcolumnstyle2_topic8.
You can download the source code from:
http://download.microsoft.com/download/5/9/f/59fb923a-12a2-4c3a-952d-d0ccccc7bf15/StylingWithTheDataGridColumnStylePart2.msi.

We cannot directly delete a specific row in the DataGrid, but we can do that via the CurrencyManager or data source. This is a code snippet:
//Method1: Remove current row via CurrencyManager.

CurrencyManager currencyManager = this.BindingContext[this.dataGrid.DataSource] as CurrencyManager;

currencyManager.RemoveAt(this.dataGrid.CurrentRowIndex);

//Method2: Remove current row via underlying DataTable.

DataTable dt = this.dataGrid.DataSource as DataTable;

dt.Rows.RemoveAt(this.dataGrid.CurrentRowIndex);

Let me know if this does not help.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, September 18, 2009 8:03 AM

Hi veerabramhendra,

We need to create our own DataGridColumnStyle to handle the button column. The article below shows how to create a DataGridButtonColumn:
http://msdn.microsoft.com/en-us/library/ms996453.aspx#datagridcolumnstyle2_topic8.
You can download the source code from:
http://download.microsoft.com/download/5/9/f/59fb923a-12a2-4c3a-952d-d0ccccc7bf15/StylingWithTheDataGridColumnStylePart2.msi.

We cannot directly delete a specific row in the DataGrid, but we can do that via the CurrencyManager or data source. This is a code snippet:
//Method1: Remove current row via CurrencyManager.

CurrencyManager currencyManager = this.BindingContext[this.dataGrid.DataSource] as CurrencyManager;

currencyManager.RemoveAt(this.dataGrid.CurrentRowIndex);

//Method2: Remove current row via underlying DataTable.

DataTable dt = this.dataGrid.DataSource as DataTable;

dt.Rows.RemoveAt(this.dataGrid.CurrentRowIndex);

Let me know if this does not help.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, September 18, 2009 8:03 AM

You can use google to search for other answers

Custom Search

More Threads

• Dataset Precision and Scale for Decimal datatype
• binding objects to DataGridView, not happening
• Best approach for loading and handling file info in a Datagridview
• UnHendleException?
• Retrieve Data From DataGridViewComboBoxColumn And Display In TextBox
• Update in gridview doesn't update the parameters
• Datagridview nullreference exception
• formatting numeric values in datagrid
• DataGridView Drag and Drop Reordering in Visual Basic
• Datagrid sort