We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Add Button control in GridDataControl

Thread ID:

Created:

Updated:

Platform:

Replies:

97222 Nov 9,2010 08:06 AM Oct 11,2013 03:31 AM WPF 5
loading
Tags: GridControl
Ramana
Asked On November 9, 2010 08:06 AM

I have a GridDataControl which I'm populating using DataTable.
Now I need to add a button control to each Row of the GridDataControl.

When the user clicks on any of the button in Row, I should be able to identify the cell on which the button is clicked.

I'm not getting on how this can be achieved.


Ponraja A [Syncfusion]
Replied On November 20, 2010 03:37 AM

Hi Ramana,

Thanks for choosing syncfusion products.

For adding the button in each row, you should set the GridDataColumnStyle as CellType="Button" as shown in the following code snippet.

[Sample Code]
[XMAL]






Using CurrencyManager we can identify RowIndex and columnIndex of currently clicked cell button. The code as follows

[Sample Code]
[C#]
int Rowindex=this.dataGrid.Model.CurrencyManager.CurrentCell.RowIndex;
int Colindex=this.dataGrid.Model.CurrencyManager.CurrentCell.ColumnIndex;

For more information please refer the attached sample.

Please let us know if you have any questions.

Thanks,
Ponraja



CS_66ab6521.zip

Ramana
Replied On November 23, 2010 12:36 AM

Hi,
Thanks for your reply.Can I know how to add the column in code instead of xaml.Since I will assign a DataTable to the Grid, I need to add the column in my code instead of xaml.


Ponraja A [Syncfusion]
Replied On November 27, 2010 04:21 AM

Hi Ramana,

Thanks for your update.

For adding the visible column in code behind, you can use the following code.

[Sample Code]
[C#]

GridDataVisibleColumn visible = new GridDataVisibleColumn();
visible.MappingName = "IsClosed";
//to set the cell type as Button
visible.ColumnStyle = new GridDataColumnStyle {CellType = "Button" };
GridDataVisibleColumn visible1 = new GridDataVisibleColumn();
visible1.MappingName = "OrderID";

this.dataGrid.VisibleColumns.Add(visible);
this.dataGrid.VisibleColumns.Add(visible1);

Please let us know if you have any questions.

Thanks,
Ponraja


Ayush Sethi
Replied On May 6, 2013 05:48 AM

Hi

I have a GridDataControl in WPF In which I have added button inside the Grid's Column But I am not able to fire the Button's Click event in ViewModel . The CoDE TO ADD button is given below But its not firing SelectAllCommand method .

<syncfusion:GridDataVisibleColumn UpdateMode="PropertyChanged" HeaderText="Rig Button" MappingName="Btntext"

>

<syncfusion:GridDataVisibleColumn.CellItemTemplate >

<DataTemplate>

<Button

Width="100" Height="30" Command="{Binding Record.Data.SelectAllCommand }" Content="{Binding Record.Data.Btntext }"

HorizontalAlignment="Left" Margin="3,0,0,0"

VerticalAlignment="Center">

</Button>

</DataTemplate>

</syncfusion:GridDataVisibleColumn.CellItemTemplate>

</syncfusion:GridDataVisibleColumn>

 


Divya A [Syncfusion]
Replied On October 11, 2013 03:31 AM

 Hi Ayush,

 

We regret for the delay caused.

 

While binding a command written in ViewModel, we should set binding using its DataContext like DataContext.SelectAllCommand. We cannot bind using Record property, as it will hold only the properties of the current record.

 

 

Code Snippet:

 

<syncfusion:GridDataVisibleColumn UpdateMode="PropertyChanged" HeaderText="Rig Button" MappingName="Btntext">

                        <syncfusion:GridDataVisibleColumn.CellItemTemplate >

                            <DataTemplate>

                                <Button Width="100" Height="30"

                                        Command="{Binding DataContext.SelectAllCommand, ElementName=_grid }"

                                        Content="{Binding Record.Data.Btntext }"

                                        HorizontalAlignment="Left" Margin="3,0,0,0"

                                        VerticalAlignment="Center">

                                </Button>

                            </DataTemplate>

                        </syncfusion:GridDataVisibleColumn.CellItemTemplate>

                    </syncfusion:GridDataVisibleColumn>

 

 

 

 

Regards,

Divya.


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;