Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i fill the first column Which is MaterialCode at runtime the autocompletebox run ok but when i edit the second column which is Desciption the first column become empty. can you give what i'm missing , Thanks.


XAML
<DataGrid AutoGenerateColumns="False" Height="162" HorizontalAlignment="Left" Margin="78,327,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="859" >

            <DataGrid.Columns>

                <DataGridTemplateColumn Header="Material Code" Width="180" x:Name="autoCompleteBox2" Selector.IsSelected="True">

                    <DataGridTemplateColumn.CellTemplate>

                        <DataTemplate>
                            <my:AutoCompleteBox Height="23" HorizontalAlignment="Left" Margin="0,0,0,0" ItemsSource="{Binding AllRoles, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" Name="autoCompleteBox1" VerticalAlignment="Top" Width="180" />
                        </DataTemplate>

                    </DataGridTemplateColumn.CellTemplate>

                </DataGridTemplateColumn>

                <DataGridTextColumn Binding="{Binding Path=Description}" Header=" Description" Width="*" />
                <DataGridTextColumn Binding="{Binding Path=Quantity}" Header=" Quantity" Width="100" />
                <DataGridComboBoxColumn x:Name="ComboBoxColumn" Header="Unit Measure"  SelectedItemBinding="{Binding Position}" Width="100" />

            </DataGrid.Columns>

        </DataGrid>


C#
public partial class SRNew : UserControl
  {
      public ObservableCollection<String> AllRoles { get; private  set; }
      public ObservableCollection<string> UnitMeasure { get; set; }
    
      

      public SRNew()
      {
          UnitMeasure = new ObservableCollection<string>() { "Pcs", "Box", "Inches" };
          InitializeComponent();
  
          var names = new ObservableCollection<String>();
          
          List<SRItems> myList = new List<SRItems>();
          ComboBoxColumn.ItemsSource = UnitMeasure;
          
          dataGrid1.ItemsSource = myList;
          var mylist = new List<string>
                           {
                               "Macedonia",
                               "Madagascar",
                               "Malawi",
                               "Malaysia",
                               "Maldives",
                               "Mali",
                               "Malta",
                               "Marshall Islands",
                               "Mauritania",
                               "Mauritius",
                               "Mexico",
                               "Micronesia",
                               "Moldova",
                               "Monaco",
                               "Mongolia",
                               "Montenegro",
                               "Morocco",
                               "Mozambique",
                               "Myanmar",

                           };
         
          for (int u = 0; u <= mylist.Count - 1; u++)
          {
              names.Add(mylist[u]);
          }

          this.AllRoles = names;
      }
      public class SRItems
      {
          public String MaterialCode { get; set; }
          public String Description { get; set; }
          public String  Quantity { get; set; }
          
      }
Posted
Updated 6-Sep-12 22:00pm
v2

1 solution

Hi,

probably you have to specify an CellEditingTemplate for the DataGridTemplateColumn.


Try this:
XML
<datagridtemplatecolumn.celleditingtemplate> 
  <datatemplate>
     <my:autocompletebox height="23" horizontalalignment="Left" margin="0,0,0,0" itemssource="{Binding AllRoles, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}" name="autoCompleteBox1" verticalalignment="Top" width="180" xmlns:my="#unknown" />
  </datatemplate>
</datagridtemplatecolumn.celleditingtemplate>


That sets the editing template to the same as your "display" template of the column.

After examining your bindings, you should add a binding to your MaterialCode property in the autocompletebox template:
XML
Text={Binding Path=MaterialCode}


Hope this helps.
 
Share this answer
 
v2
Comments
Bertdecode 7-Sep-12 9:10am    
I tried that also but still the problem occur.
Thomas Duwe 7-Sep-12 9:36am    
Then maybe this has something to do with your autocompletebox not updating it's Text property. But without the code for you autocompletebox, I can't do anything further to help you.
Thomas Duwe 8-Sep-12 6:36am    
No, I see nothing wrong with your bindings, but you have no binding to your MaterialCode property in the grid-xaml.

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