DataGridComboxColumn

Jan 5, 2010 at 6:55 AM

Hi All

I've problem with the DataGridComboxColumn.

My Database-Design looks like this:
Table Order:
OrderID (PK)
Description
CustomerID (FK to Customer)

Table Customer
CustomerID (PK)
Name

Isn't it possible to show all orders in the DataGrid (no Problem) but for the Customer I want a DataGridComboxColumn
in which I want display all possible Customers and the possibility to change the orders Customers.

I'm trying this with the Entity FrameWork and Linq

Jan 15, 2010 at 4:26 PM

hi shogun,

try this:

1. Add into XAML the "DataGridComboBoxColum" column.

<toolkit:DataGrid AutoGenerateColumns="False" Name="grdOrders" ...>
    <toolkit:DataGrid.Columns>
        .
        .
        .
        <toolkit:DataGridComboBoxColumn x:Name="colCustomer" />        
    </toolkit:DataGrid.Columns>    
</toolkit:DataGrid>

2. Add the following code:

this.colCustomer.Header = "Customer Name";                

//add the list to the combobox here: the list "CustomerTable" could be a System.Data.DataTable BindingOperations.SetBinding(this.colCustomer, DataGridComboBoxColumn.ItemsSourceProperty, new System.Windows.Data.Binding() { Source = CustomerTable });

//select binding for "CustomerID" property in the Order Table (DataGrid) this.colCustomer.SelectedValueBinding = new System.Windows.Data.Binding("CustomerID");

//set related ID in Customer Table: "CustomerID" is the name of the property in the Customer Table list this.colCustomer.SelectedValuePath="CustomerID";

//in the combox this name is shown and it's reacts to the keyboard this.colCustomer.DisplayMemberPath="Name";


and that's it!

But I have myself a question: When I tab thru the other columns the cells (Text) go right into edit mode,
but when I hit the cell with the DataGridComboBoxColum I have to click the tab twice to get into edit mode.
This happens also to DataGridCheckBoxColumn columns!

Why this? And I would like to know, how to avoid this!

Would be really really kind if someone could give any hint!

Michael


 

 

 

 

Jan 29, 2010 at 2:02 AM
Edited Jan 29, 2010 at 2:07 AM

See below...

Jan 29, 2010 at 2:06 AM
navigato wrote:

But I have myself a question: When I tab thru the other columns the cells (Text) go right into edit mode,
but when I hit the cell with the DataGridComboBoxColum I have to click the tab twice to get into edit mode.
This happens also to DataGridCheckBoxColumn columns!

Why this? And I would like to know, how to avoid this!

Would be really really kind if someone could give any hint!

Michael


navigato,

 

I'm rather new to WPF myself, but I also ran into this issue when using a template column.  I found a solution to this on another site a while back.  I can't remember the reason they said for needing to tab twice, but I think it was something about the custom control being put inside a content presenter or something like that.  Anyway, here is how I got around the problem using a grid with a binding for FocusedElement:

 

<dg:DataGridTemplateColumn>
<dg:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<Grid FocusManager.FocusedElement="{Binding ElementName=MyAutoTextBox}">
<local:AutoCompleteTextBox x:Name="MyAutoTextBox" />
</Grid>
</DataTemplate>
</dg:DataGridTemplateColumn.CellEditingTemplate>
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
...
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>

Hope this helps!