Home Forums WPF controls Xceed DataGrid for WPF Finding a specified control in the Main Column

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #23417 |

    Hi

    In my Grid, I’ve created a CellContentTemplated main column with the CheckBox Control.

    I want to find a CheckBox in the main column and make it as checked.

    To achieve this, I tried somewhat like

    mygrd.Columns.MainColumn.CellContentTemplate.FindName(“ckbox1”,XXXXX);

    But this statement throws error messages. What Comes for XXXXX ?

    What Should I Do?

    Thanks in advance

    Regards
    Sathanantham

    Imported from legacy forums. Posted by Satheesh (had 2913 views)

    Xceed Support
    Member
    Post count: 5658

    CellContentTemplate is applied on a Cell’s ContentPresenter, to retrieve the named control in the Cell’s CellContentTemplate, pass the Cell to the FindName method.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 490 views)

    User (Old forums)
    Member
    Post count: 23064

    DataRow rowUser1 = dataGridControl2.GetContainerFromItem(dataGridControl2.CurrentItem) as DataRow;
    ContentPresenter myContentPresenter = FindVisualChild<ContentPresenter>(rowUser1);
    DataTemplate myTemplate = (DataTemplate)this.Resources[“CheckBoxCell”];

    CheckBox retrievedCheckBox = (CheckBox)myTemplate.FindName(“chkRole”, myContentPresenter);
    retrievedCheckBox.IsChecked = true;

    Imported from legacy forums. Posted by Pawan (had 3108 views)

    User (Old forums)
    Member
    Post count: 23064

    I have tried that code but it doesn’t work.

    XAML

      <my1:DataGridControl 
                        Name=”marketTypesDataGrid”
                        AutoCreateColumns=”False”
                        NavigationBehavior=”RowOnly”
                        ItemsSource=”{Binding Source={StaticResource viewModel}, Path=MarketTypes}” Margin=”12,135,9,69″>
                        <xcdg:DataGridControl.View>
                            <xcdg:TableView UseDefaultHeadersFooters=”False”>
                                <xcdg:TableView.FixedHeaders>
                                    <DataTemplate>
                                        <xcdg:ColumnManagerRow />
                                    </DataTemplate>
                                </xcdg:TableView.FixedHeaders>
                            </xcdg:TableView>
                        </xcdg:DataGridControl.View>
                        <my1:DataGridControl.Columns>                     
                            <!– The column “Status” should be Unbound Column but it can’t be done with Xceed Datagrid so the bound column has to be used but it won’t be using in DataTemplate. Note: This is a trick. –>
                            <my1:Column FieldName=”PeriodId” Title=”Status” Width=”50″>
                                <my1:Column.CellContentTemplate>                               
                                    <DataTemplate>
                                        <CheckBox Name=”statusCheckBox”                                           
                                            Command=”{Binding Source={StaticResource viewModel}, Path=SelectMarketType}”                                       
                                            CommandParameter=”{Binding SelectedItem, ElementName=marketTypesDataGrid}”                                              
                                        />
                                    </DataTemplate>
                                </my1:Column.CellContentTemplate>
                            </my1:Column>
                        </my1:DataGridControl.Columns>
                    </my1:DataGridControl>

    C#

               private childItem FindVisualChild<childItem>(DependencyObject obj) where childItem : DependencyObject {
                if (obj == null) return null;
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) {
                    DependencyObject child = VisualTreeHelper.GetChild(obj, i);
                    if (child != null && child is childItem)
                        return (childItem)child;
                    else {
                        childItem childOfChild = FindVisualChild<childItem>(child);
                        if (childOfChild != null)
                            return childOfChild;
                    }
                }
                return null;
            }

    –Attempt 1 <not working>

     foreach (var itm in marketTypesDataGrid.Items) {
                    Row myRow = marketTypesDataGrid.GetContainerFromItem(itm) as Row;
                    ContentPresenter myContentPresenter1 = FindVisualChild<ContentPresenter>(myRow);
                    if (myContentPresenter1 != null) {
                        DataTemplate myDataTemplate1 = myContentPresenter1.ContentTemplate;
                        if (myDataTemplate1 != null) {
                            CheckBox statusCheckBox1 = (CheckBox)myDataTemplate1.FindName(“statusCheckBox”, myContentPresenter1);
                        }
                    }
                }

     –Attempt 2 <not working>

     foreach (var itm in marketTypesDataGrid.Items) {
                    Row myRow = marketTypesDataGrid.GetContainerFromItem(itm) as Row;               
                    if (myRow != null) {
                        Cell cel = myRow.Cells[MARKETTYPE_STATUS_COL_IDX];                   
                        // Getting the ContentPresenter of myListBoxItem
                        ContentPresenter myContentPresenter = FindVisualChild<ContentPresenter>(cel);
                        if (myContentPresenter != null) {
                            DataTemplate myDataTemplate = myContentPresenter.ContentTemplate;
                            if (myDataTemplate != null) {
                                CheckBox statusCheckBox = (CheckBox)myDataTemplate.FindName(“statusCheckBox”, myContentPresenter);
                            }
                        }
                    }
                }

    There are some many attempts that I made but not working. Could you please help me to solve that problem?

     

    Imported from legacy forums. Posted by Michael (had 921 views)

    User (Old forums)
    Member
    Post count: 23064

    If I put the datatemplate in Resource, I’m able to get the reference of control. but another problem comes. How can I show all rows without lazy-binding?

    Imported from legacy forums. Posted by Michael (had 1649 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.