Add Button control in GridDataControl

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.


5 Replies

PA Ponraja A Syncfusion Team November 20, 2010 08:37 AM UTC

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


RA Ramana November 23, 2010 05:36 AM UTC

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.



PA Ponraja A Syncfusion Team November 27, 2010 09:21 AM UTC

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



AS Ayush Sethi May 6, 2013 09:48 AM UTC

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>

 



DA Divya A Syncfusion Team October 11, 2013 07:31 AM UTC

 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.


Loader.
Up arrow icon