Add Button control in GridDataControl
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.
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
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.
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
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>
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.
- 5 Replies
- 4 Participants
-
RA Ramana
- Nov 9, 2010 01:06 PM UTC
- Oct 11, 2013 07:31 AM UTC