.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

databinding combobox which is inside a datagridtemplatecolumn

Posted By:      Posted Date: September 07, 2010    Points: 0   Category :WPF
My datagrid is bound to a datacontext and I have a combobox inside a template column which has to be bound to a data source out of the existing datacontext.  I couldnt access that combobox from code behind. How can I achieve this. Also may i have a good learning resources for styling datagrid. Thanks :)   EDIT: I have two datatables in a dataset and my need is to intermix the data from both. Initially i set the data context to dataset.table1. Now I wanted to get values from other. So I tried the code-behind and found that I cant access elements in the datatemplate.   EDIT 2: I tried something like this: From code-behind: set Me.DataContext=mydataset And in XAML: when I wanted the values from 1st datatable: set the binding to table1/field. But I could see oly the first row of the datatable. 

View Complete Post

More Related Resource Links

How to get the combobox value inside Datagrid on Edit button click event

Hi     I have Datagrid template column like<DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn>DataGridTemplateColumn Header="Edit" x:Name="Edit" ><DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn.CellEditingTemplate></DataGridTemplateColumn>SelectionChanged="cmbDGTeam_SelectionChanged" IsTabStop="True" /></DataTemplate><ComboBox Height="22" IsEditable="True" IsReadOnly="True" ItemsSource="{Binding}" DisplayMemberPath="Title" SelectedValuePath="TeamID" x:Name="cmbDGTeam"  SelectedValue="{Binding Path=TeamID,Mode=TwoWay}"<DataGridTemplateColumn.CellEditingTemplate><DataTemplate><DataTemplate><TextBlock Text="{Binding Title}"/></DataTemplate></DataGridTemplateColumn.CellTemplate><DataGridTemplateColumn Header="Team" Width="75"><DataGridTemplateColumn.CellTemplate> and Edit button Template column <DataGridTemplateColumn Header="Edit" x:Name="Edit" > </DataGridTemplateColumn.CellTemplate></DataTemplate><Button Content="Edit" IsEnabled="False" x:Name="btnEdit" Click="btnEdit_Click" ></Button>&l

Accessing Combobox inside WPF Datagrid Template Column

Hi, I am creating a WPF datagrid template column with combobox. The problem that I face now is, I am not able to bind a table to the combobox inside the WPF datagrid template column. Here is the code snippet. <dg:DataGrid x:Name="Students" AutoGenerateColumns="False" Loaded="OnLoad"> <dg:DataGrid.Columns> <dg:DataGridTextColumn Binding="{Binding Path=Name}" Header="Name" Width="75"/> <dg:DataGridTemplateColumn x:Name="Dept"> <dg:DataGridTemplateColumn.CellTemplate> <DataTemplate> <ComboBox x:Name="DeptId" ItemsSource="{Binding}" SelectionChanged="Dept_SelectionChanged" DisplayMemberPath="{Binding Path=DeptName}" SelectedValuePath="{Binding Path=DeptId}" SelectedItem="{Binding Path=Belongs}"/> </DataTemplate> </dg:DataGridTemplateColumn.CellTemplate> </dg:DataGridTemplateColumn> </dg:DataGrid.Columns> </dg:DataGrid> Please help me to find out the way to assign a dynamic source to the combobox through code behind file. Thanks in Advance!!! Best Regards, Subalakshmi Vijayarajan.

Display the item in the ComboBox inside the ListView(GridView)

I have the below code used in binding the values to the ComboBox in GridView(ListView), please help me < ListView Margin="480,51,6,14" Name="grid1" ItemsSource="{Binding UserDetail}" IsSynchronizedWithCurrentItem="True" Width="389" Grid.Column="1" > <ListView.View> <GridView> <GridViewColumn Header="UserName" Width="120" DisplayMemberBinding="{Binding Path=WindowsUser}"/> <GridViewColumn Header="Role" Width="140"> <GridViewColumn.CellTemplate> <DataTemplate> <ComboBox Name="Rolecombo" Width="120" ItemsSource="{Binding Path=UserDetail}" SelectedValue="{Binding PFR_Tbl_Role.Role}"/> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Header="Active" x:Name="column" Width="100"> <GridViewColumn.CellTemplate> <DataTemplate> <Grid Width="{Binding ElementName=column,Path=Width}"> <CheckBox IsChecked="{Binding Active}" HorizontalAlignment="Center" /> </Grid> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView>  </ListView.View> </ListView>

Click.CommandParameter null when binding on Button inside DataGrid DataGridTemplateColumn

I am having trouble getting a Click.CommandParameter to pass through with a bound Click.Command. I have a DataGrid with a DataGridTemplateColumn that contains a couple of Buttons. Using a suggestion found on the forum (http://social.msdn.microsoft.com/Forums/en/wpf/thread/541024a9-3d7e-4c6a-b88e-9a7eb7ee83a9), I was able to get the Click.Command to bind to the right command, but when arriving in the corresponding method in my ViewModel, the parameter is null.  Here is my xaml for my DataGridTemplateColumn <data:DataGridTemplateColumn Header="Case">  <data:DataGridTemplateColumn.CellTemplate>   <DataTemplate >    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">     <Button Content="Open" Margin="6,0" command:Click.Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type data:DataGrid}}, Path=DataContext.OpenCaseCommand}" CommandParameter="{Binding}"  />     <Path Data="M1,1 L1,2" Stroke="#FFCCCCCC"/>     <Button Content="Rename" />    </StackPanel>   </DataTemplate>  </data:DataGridTemplateColumn.CellTemplate> </data:DataGridTemplateColumn> I used Snoop to see what was going on. Everything

Problem with IE 6 in displaying colours inside a Combobox


I have a dropdownlist which has to display the list of colours. It works fine in IE 7 and IE 8 but in IE 6 I am not able to see the Colours or the dropdownlist when I scroll the toolbar down as i have long list of colours. Is it happening because something is hiding the coloured dropdownlist?

DropDownList lstSeriesColours = new DropDownList();

lstSeriesColours.ID = string.Format("lstSeriesColours_{0}", rowID);Unit.Pixel(80);"Name";"Value";

lstSeriesColours.DataTextField = "Name";

lstSeriesColours.DataValueField = "Value";


Select multiple checkboxes placed inside a combobox



I have just started working on WPF and I am fairly new to this technology. I need to add a excel filter like functionality for datagrid control. I have successfully added a combobox(with checkboxes inside) in the header of the datagrid. The datagrid needs to display "All" as first checkbox. If user checks this first checkbox all other checkboxes(inside same combo) need to be checked automatically. Following is my datatemplate for combo. I have placed in column header combo through codebehind.

<DataTemplate x:Key="comboTemplate">

   <ComboBox Name="cboTask" Loaded="cboTask_Loaded" Wid

DataGridTemplateColumn not accepting/updating to new value from CellEditTemplate.ComboBox


Given: a DataGridTemplateColumn with a CellTemplate displaying a TextBlock and a CellEditTemplate with a Combobox
If the user selects an Combo-Item it shall become the new selection of the row.
How can this be achieved?
Right now the new value is dismissed when editing is finished.
The previous value is still the one displayed and selected.


<DataGrid x:Name="DG" AutoGenerateColumns="False" CanUserAddRows="False">

Looking for more complex WPF databinding ComboBox sample


Hi, I'm just picking up WPF. I'm looking for a samples that show you a more realistic way to bind data to a ComboBox? The one in the SDK doesn't show me what I need.


I have a Person class that I load from dB into a DataSet. That class is bound to text boxes on my WPF form. I have two way data binding. No problems here. One of the Person's address fields is "state". I don't want the user to edit the state abbreviation directly, but instead want to limit the choices from another data table. Which means I have to bind the combobox to the data tabe, but are unsure how to connect/bind it also with the person class so when the selection changes it gets reflected in the person class.


Can this be done just via XAML? Or do I have to write code on combobox.SlectionChanged()  to make explicit changes to the Person class?



Ajax Controls - ComboBox inside updatepanel




I have a web part which has an updatepanel with variuos panels.

When i add a combobox to a panel which is not shown to begin with but then is set to visible = true, the combobox erros and is not displayed correctly.


If i have one combobox already visible and working fine, then the others are OK - but thats not a solution.


How do i have a combobox inspde a hidden panel and then show it without having to rebind the whole page.




ComboBox with Custom ItemsSource DataBinding Issue



I'm using VS2010 and .NET 4 do create a WPF application. I've a dataset with, say two tables: Patients and MyValues. Patients contains PatientID, FirstName, LastName and Gender. Gender stores "1" or "2" for "Male" and "Female", respectively. MyValues contains DomainID, ColValue (e.g., "1"), and ValueDesc (e.g., "Male"). I've stored the Patient.Gender's DomainID as an ExtendedProperty foir the column in the dataset. I've created a form by dragging and dropping the Patient Details onto a WPF form after setting the Gender's default control to a ComboBox in the DataSources window.

At runtime, I populate the ComboBox items from the MyValues table with a LINQ query as shown below. The ComboBox gets populated correctly, showing "Male" and "Female", and the SelectedValues are also correct. I have not been able to figure out how to hook up the SelectedValue to the Gender field (my Bindidng b below). Any help would be appreciated.



Combobox inside Listbox binding issue

I am lost...

I have the following two classes (simplified)

Class Parent
    String Description{get;set;} 
    ObservableCollection<Children> ListOfChildren = new ObservableCollection<Children>();

Class Children
    public string Name{get;set;}

And the following two lists :

public List<Parent> ListOfParents = new List<Parent>();
public static List<Children> StaticListOfChildren=new List<Children>();

Now I have a list in XAML, I set the datacontext of this list to the "ListOfParents" (in code) and set the ItemSource="{Binding}"
All works fine so far. Inside this list I have another list containing the "ListOfChildren" list. The itemtemplate of this list contains a combobox. This combobox binds to the "StaticListOfChildren" list. The problem is now I can't get the selecteditem of the combobox to bind to the Children item in the ListOfChildren.... Can anyone help ??

<ListBox x:Name="lbMaterialsBuildup" HorizontalContentAlignment="Stretch" ItemsSource="{Binding}">

Accessing the different controls inside a GridView control

how we can access a particular control which resides inside a GridView control. In this article I will show you how you can access different controls inside a GridView control. We will see how we can access a TextBox control, a DropDownList control and a ListBox control. If you are working with ASP.NET 1.X then you might want to check out my article Accessing Different Controls Inside a DataGrid.

How To Add calendar control inside a GridView

This article show hot to add calendar control inside a GridView with code in c#

Using ATLAS PopUp Control with Calendar inside the GridView Control

In this video tutorial Mohammad demonstrates how you can access the Calendar control which is displayed using the ATLAS PopUp control inside the GridView control.

RadioButton inside GridView, How to get it work as normal

Did you tried before to drag a RadioButton control inside a Gridivew templatefield, and then you attempt to select these RadioButtons , you will notice that the behavior of RadioButton control will be changed and it will work just like the behavior of checkbox control! the user will be able to select more than one radiobutton in the grid!

Maintain HTML Radio Button Selection Inside GridView After Postback

Long time ago I wrote an article about getting the value of the selected RadioButtons inside the GridView control. The code did not addresssed the postback issue which means that the selected radio button was cleared after the postback occurs.

LinkButton inside Repeater



I have Repeater, which consists of LinkButon and Literal. LinkButon and Literal are whole thing by implication. I want get value from Literal, when user click on corresponding LinkButton.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend