8 Replies - 735 Views - Last Post: 07 September 2012 - 11:54 AM Rate Topic: -----

#1 Bertdecode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 06-September 12

Datagrid with autocompletebox under DataGridTemplateColumn

Posted 06 September 2012 - 07:25 AM

When i fill the column of 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 that what i'm missing , Thanks.

<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>






  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(Convert.ToString(mylist[u]));
            }

            this.AllRoles = names;
        }
        public class SRItems
        {
            public String MaterialCode { get; set; }
            public String Description { get; set; }
            public String  Quantity { get; set; }
            
        }



Is This A Good Question/Topic? 0
  • +

Replies To: Datagrid with autocompletebox under DataGridTemplateColumn

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 1890
  • View blog
  • Posts: 5,680
  • Joined: 05-May 12

Re: Datagrid with autocompletebox under DataGridTemplateColumn

Posted 06 September 2012 - 07:51 AM

Shouldn't this be in the WPF or Silverlight forum?

As a quick aside, on line 45 of the C# code, why do you need to convert mylist[u] to string when it is already a string?

This post has been edited by Skydiver: 06 September 2012 - 08:01 AM

Was This Post Helpful? 0
  • +
  • -

#3 Bertdecode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 06-September 12

Re: Datagrid with autocompletebox under DataGridTemplateColumn

Posted 06 September 2012 - 08:03 AM

yes, i forgot to change it, the reason i convert it to string is because i use Integer and other form, so forget that, my problem is when i fill the first column the autocompletebox is ok but when tried to fill the second the first column become empty. what do you think the reason why is it happen?
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 1890
  • View blog
  • Posts: 5,680
  • Joined: 05-May 12

Re: Datagrid with autocompletebox under DataGridTemplateColumn

Posted 06 September 2012 - 08:27 AM

Off the top of my head, I'm seeing a binding for the ItemsSource, but I'm not seeing a binding to where the actual value the user types in gets stored.
Was This Post Helpful? 0
  • +
  • -

#5 Bertdecode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 06-September 12

Re: Datagrid with autocompletebox under DataGridTemplateColumn

Posted 06 September 2012 - 08:50 AM

ok i got your point, i tried to work with that ,and then i inform you after. thanks
Was This Post Helpful? 0
  • +
  • -

#6 Bertdecode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 06-September 12

Re: Datagrid with autocompletebox under DataGridTemplateColumn

Posted 07 September 2012 - 12:33 AM

unfortunately i can't make it work, the problem is still occur.
Any help is appreciated... Thanks
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 1890
  • View blog
  • Posts: 5,680
  • Joined: 05-May 12

Re: Datagrid with autocompletebox under DataGridTemplateColumn

Posted 07 September 2012 - 01:33 AM

Can you post your new code with the binding?
Was This Post Helpful? 0
  • +
  • -

#8 Bertdecode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 06-September 12

Re: Datagrid with autocompletebox under DataGridTemplateColumn

Posted 07 September 2012 - 06:08 AM

I modify the itemsource of datagrid by adding MaterialCode where the First column of datagrid stored the data.

 public class SRItems
        {
            public string MaterialCode { get; set; }
            public string Description { get; set; }
            public string  Quantity { get; set; }
            
        }

and then also adding binding to autocompletebox

 <DataGridTemplateColumn FocusManager.FocusedElement="{Binding ElementName= autoCompleteBox1}" Header="Material Code" Width="180" x:Name="autoCompleteBox2">

                    <DataGridTemplateColumn.CellTemplate >
                        <DataTemplate >
                            <TextBlock  Text="{Binding MaterialCode}" />                                
                        </DataTemplate>
                        
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>

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

                    </DataGridTemplateColumn.CellEditingTemplate>

                </DataGridTemplateColumn>

Was This Post Helpful? 0
  • +
  • -

#9 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 1890
  • View blog
  • Posts: 5,680
  • Joined: 05-May 12

Re: Datagrid with autocompletebox under DataGridTemplateColumn

Posted 07 September 2012 - 11:54 AM

Thanks.

That is strange. I don't know what to tell you.

If instead of AutoCompleteBox, you used a plain old TextBox, does it work? If it does, have you tried moving up to a ComboBox? And if the ComboBox still works, then switching back to the AutoCompleteBox in theory should also work, but as you've observed it doesn't. It maybe time to download the source for the AutoCompleteBox and set breakpoints within it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1