Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
2.25/5 (3 votes)
See more:
hi,

how can we send the grid's content to textboxes when we click on the Details button

this is the grid view code :
i have 3 columns and 1 button for each row
and i have 3 textboxes


XML
<telerik:RadGridView  Grid.Row="1" Name="dtgAttachment" AutoGenerateColumns="False" EnableRowVirtualization="True"   ItemsSource="{Binding}"  RowDetailsVisibilityMode="VisibleWhenSelected" >
    <telerik:RadGridView.Columns>
        <telerik:GridViewColumn>
            <telerik:GridViewColumn.CellTemplate>
                <DataTemplate>
                    <telerik:RadButton Content="Details" Name="btnDetails" Click="btnDetails_Click" IsEnabled="True" CommandParameter="{Binding}"/>
                </DataTemplate>
            </telerik:GridViewColumn.CellTemplate>
        </telerik:GridViewColumn>
        <telerik:GridViewDataColumn   x:Name="dtgAttachmentId" DataMemberBinding="{Binding Path=attachment_id}" Header="{x:Static locala:ResourceProject.lblAttachmentId}" Width="SizeToHeader" />
        <telerik:GridViewDataColumn  x:Name="dtgName" DataMemberBinding="{Binding Path=attachment_name}" Header="{x:Static locala:ResourceProject.lblNameAttachment}" Width="SizeToHeader" />
        <telerik:GridViewDataColumn  x:Name="dtgPrice" DataMemberBinding="{Binding Path=attachment_price}" Header="Price" Width="SizeToHeader" />
    </telerik:RadGridView.Columns>
</telerik:RadGridView>


please help.......
Posted
Comments
Mark Salsbery 4-Jun-11 14:05pm    
What are you asking? What "grid's content"? What "textboxes"? That XAML doesn't show anything relevant.
Vivek Krishnamurthy 7-Jun-11 5:49am    
You have a GridView with 3 columns. And the forth column is a button. Click on the button you want to show details of that row in the respective text boxes outside the gridview.

Is this understanding right ?

thank you very much for solution
look
i find solution

i remove button
and i have just GridView with 3 columns and 3 textBox

i use event MouseDoubleClick in GridView

like this:

XML
<telerik:RadGridView   Grid.Row="1" Name="dtgAttachment" AutoGenerateColumns="False" EnableRowVirtualization="True"   ItemsSource="{Binding}"  RowDetailsVisibilityMode="VisibleWhenSelected" MouseDoubleClick="dtgAttachment_MouseDoubleClick" >
           <telerik:RadGridView.Columns>
               <telerik:GridViewColumn>
                  </telerik:GridViewColumn>
               <telerik:GridViewDataColumn   x:Name="dtgAttachmentId" DataMemberBinding="{Binding Path=attachment_id}" Header="{x:Static localo:Resource.dtgAttachmentId}" Width="SizeToHeader" />
               <telerik:GridViewDataColumn  x:Name="dtgName" DataMemberBinding="{Binding Path=attachment_name}" Header="{x:Static localo:Resource.dtgName}" Width="SizeToHeader" />
               <telerik:GridViewDataColumn  x:Name="dtgPrice" DataMemberBinding="{Binding Path=attachment_price}" Header="{x:Static localo:Resource.dtgPrice}" Width="SizeToHeader" />
           </telerik:RadGridView.Columns>
       </telerik:RadGridView>




and in Code C# i write this Code
C#
private void dtgAttachment_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            attachment_tab a = dtgAttachment.SelectedItem as attachment_tab;
            if (a != null)
            {
                var g = from d in Program.Context.attachment_tab
                        where d.attachment_id == a.attachment_id
                        select d;
                txtbAttachmentId.Text = g.FirstOrDefault().attachment_id.ToString();
               txtNameAttachment.Text = g.FirstOrDefault().attachment_name;
                txtPriceAttachment.Text = g.FirstOrDefault().attachment_price.ToString();
            }
            else
                MessageBox.Show("There is no data");
        }



thank you for help...........
 
Share this answer
 
Solution 1

Define SelectCommand in class where you have 'attachment_id', 'attachment_name', 'attachment_price' properties.

XML
<telerik:RadButton Content="Details" Name="btnDetails" Command="{Binding SelectCommand}" IsEnabled="True" CommandParameter="{Binding}"/>


Define SelectCommand execution in parent who is holding above collection. Pass the parent SelectCommand to individual object of above collection.

In your command execution, assign data you are receiving through CommandParameter binding as DataContext to Parent of your other TextBoxes.

Note: I am assuming you are following MVVM pattern here.


solution 2

Extract CommandParemeter in btnDetails_Click event handler from sender by casting it to RadButton.
Pass this CommandParemeter as DataContext to control who is hosting all other textboxes.
 
Share this answer
 
v2
connecting sql databse throuh give textbox value view all data in girdviewdetails
in javacoding
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900