Get controls inside grid rows

8 posts, 0 answers
  1. Alex
    Alex avatar
    16 posts
    Member since:
    Sep 2010

    Posted 28 Sep 2010 Link to this post

    Hi,
    I have a grid populated dinamicaly with several columns including a textbox  a combo box and a button.
    Initally the button and the combo are disabled.

    <telerik:RadGridView x:Name="RadGridView2" Width="auto"  Margin="8,180,5,113" RowIndicatorVisibility="Collapsed" ShowGroupPanel="False" AutoGenerateColumns="false" ItemsSource="{Binding GridInformationInsurance}" RowActivated="RadGridView2_RowActivated">
                 <telerik:RadGridView.Columns >
                 <telerik:GridViewDataColumn DataMemberBinding="{Binding ID}" Width="75" TextAlignment="Center"  Header="Calc" IsReadOnly="True" >
                 <telerik:GridViewDataColumn.CellTemplate >
                 <DataTemplate>
                 <StackPanel>
                 <telerik:RadButton x:Name="btnCalc" Width="50" IsEnabled="False" Height="21" Margin="0,0,10,0" HorizontalAlignment="Right" Content="פרעון" VerticalAlignment="Center"/>
                 </StackPanel>
                 </DataTemplate>
                 </telerik:GridViewDataColumn.CellTemplate>
                 </telerik:GridViewDataColumn>
    <telerik:GridViewDataColumn DataMemberBinding="{Binding ID}" Width="90" TextAlignment="Center"  Header="Calc Meth" IsReadOnly="True" >
                <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                <Grid>
                <telerik:RadComboBox x:Name="cmbCalcMeth" SelectedIndex="0" IsEnabled="False">
                <telerik:RadComboBoxItem Content="לפי המלצה"/>
    <telerik:RadComboBoxItem Content="לפי חודש קודם"/>      
    </telerik:RadComboBox>  
    </Grid>    
    </DataTemplate>    
    </telerik:GridViewDataColumn.CellTemplate>
                
    </telerik:GridViewDataColumn>

                 <telerik:GridViewDataColumn Width="70"  Header="Amount" DataMemberBinding="{Binding Amount, Mode=TwoWay}"  TextAlignment="Center">
                 <telerik:GridViewDataColumn.CellTemplate >
                 <DataTemplate>
                 <StackPanel>
                 <TextBox x:Name="txtCalc" Width="40" Height="21" Margin="0,2,0,0" HorizontalAlignment="Right" Text="" TextInputStart="EnableCalcMethod"/>
                 <TextBlock Text="₪" Height="21" Width="auto" Margin="0,-20,52,0" HorizontalAlignment="Right"/>
                 </StackPanel>
                 </DataTemplate>
                 </telerik:GridViewDataColumn.CellTemplate>            
                 </telerik:GridViewDataColumn>
                


    What I need to happen is when I right something in the textbox the button and the combo on the same row to be enabled.
    I atached to the TextInputStart of the textbox a function where i try to get from there to the row parent and acces the other columns but it doesn't seam to work as I get null.

    private void EnableCalcMethod(object sender, System.Windows.Input.TextCompositionEventArgs e)
            {
             // TODO: Add event handler implementation here.
              
                CheckBox chk = new CheckBox();         
           
                TextBox txt = sender as TextBox;            

                MessageBox.Show("" + txt.ToString());
                StackPanel stp = (StackPanel)txt.Parent;
                MessageBox.Show("" + stp.ToString());
                if (stp.Parent != null)
                    MessageBox.Show("" + stp.Parent.ToString());
                else
                    MessageBox.Show("null");

    THIS IS WHERE I GET NULL

    Anyway I am not sure  if I get the parent row if it would help.

    Any other ideas, or any ideas?:)

    Thanks a lot,
    Alex

  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 28 Sep 2010 Link to this post

    Hi Alex,

    You may use the extension methods - ChildrenOfType<> and ParentOfType<>. Thus, the implementation of the TextInputStart event may look like:

    private void txtCalc_TextInputStart(object sender, TextCompositionEventArgs e)
    {
        TextBox textBox = sender as TextBox;
        GridViewRow parentRow = textBox.ParentOfType<GridViewRow>();
     
        RadComboBox combo = parentRow.ChildrenOfType<RadComboBox>().FirstOrDefault();
        RadButton button = parentRow.ChildrenOfType<RadButton>().FirstOrDefault();
     
        if (combo != null && button != null)
        {
            combo.IsEnabled = true;
            button.IsEnabled = true;
        }
    }
     
    You may take a look at this blog post for further reference.

    Kind regards,
    Maya
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Alex
    Alex avatar
    16 posts
    Member since:
    Sep 2010

    Posted 28 Sep 2010 Link to this post

    Hi Maya,

    That worked great.

    Thanks,
    Alex
  4. Alex
    Alex avatar
    16 posts
    Member since:
    Sep 2010

    Posted 04 Oct 2010 Link to this post

    Hi,

    Is there anyway I can implement this using Commands instead of actions?

    From what I know the command defualt trigger is click but I need it to be key up. Is this possible?How?



    Thanks a lot,
    Alex
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 04 Oct 2010 Link to this post

    Hello Alex,

    Unfortunately, I am not quite sure what is your exact requirement. Do you want to create a command handling the enabling/disabling of some elements/ cells ? So, in order to provide you with an appropriate answer, I would need a bit more information about your scenario. 
     

    Kind regards,
    Maya
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Alex
    Alex avatar
    16 posts
    Member since:
    Sep 2010

    Posted 04 Oct 2010 Link to this post

    Hi Maya,

    What I need to do is the following:
    The scenario is the same as the first post , I have a RadGridView with some columns. Among them a button  textbox, a checkbox and a dropdown. The  button , the dropdown are disabled.

    When I write something inside the textbox the button and the dropdown should be enabled(only for the specific row)

    What is changed now is that I have to use MVVM and commands instead of KeyUp event of the textbox.
    Somehow I managed to find a piece of code that  helps me trigger the event of KeyUp using commands. 

    This helped
    http://www.telerik.com/community/forums/silverlight/gridview/using-image-control-in-grid-to-delete-row-instead-of-button-using-mvvm.aspx

    My problem now is how to acces form inside de ViewModel the button and the dropdown from the same row,

    let's say inside 
    public void MyMethod from the example (among last posts)


    Thanks,
    Alex
  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 04 Oct 2010 Link to this post

    Hello Alex,

    The basic idea behind the Model-View-ViewModel Design Pattern is to separate the view from the data, using the ViewModel. Thus, following up your requirements, it will be beyond that concept to make the ViewModel aware of the visual elements in the application. So, I would recommend you to use the approach demonstrated above, handling the TextInputStart event. 
     

    Best wishes,
    Maya
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Spoorthy
    Spoorthy avatar
    8 posts
    Member since:
    Feb 2012

    Posted 12 Mar 2012 Link to this post

    Hi Maya,

    Please let me know

    How can I get the value of TextBox present inside the row of RadGridView using MVVM ? I need to insert the particular value in the database in ViewModel.

    The property value is binded with the TextBox value if it is present outside the RadGridView but when placed inside RadGridView ,the property value for the TextBox is becoming null.

    Thanks in advance
Back to Top