0

i've got a datagrid, in it i've a column that is combobox, for binding i've binded with a list. when i run my appli, when i change the value in at combobox, it changes correctly, until here i don't have probleme, but when i select another row the value that was changed in combobox reset and it appears that it was never changed!!! what i have to do?

in xaml:

<DataGrid HorizontalAlignment="Left" CanUserAddRows="True" Height="161" Margin="162,370,0,0" VerticalAlignment="Top" Width="558" Name="da" SelectionChanged="da_SelectionChanged" IsReadOnly="False" IsHitTestVisible="True" AutoGenerateColumns="False" ItemsSource="{Binding DataCollection,Mode=TwoWay}">
                    <DataGrid.Columns>
                        <DataGridComboBoxColumn Header="Ref OSS2" MinWidth="100" x:Name="CMBXREF" IsReadOnly="False" CanUserReorder="True">
                        </DataGridComboBoxColumn>
                        <DataGridTextColumn Header="IP" IsReadOnly="False" Binding="{Binding Path=IP}" MinWidth="100"/>
                        <DataGridTextColumn Header="Ref OSS" IsReadOnly="True" Binding="{Binding Path=REF_OSS}" MinWidth="100"/>
                        <DataGridTextColumn Header="Name" IsReadOnly="False" Binding="{Binding Path=NAME}" MinWidth="100"/>
                        <DataGridTextColumn Header="Quntity" IsReadOnly="False" Binding="{Binding Path=QUNTITY}"/>
                        <DataGridTextColumn Header="Comments" IsReadOnly="False" Binding="{Binding Path=COMMENT}" MinWidth="100"/>
                    </DataGrid.Columns>


                </DataGrid>

and i've binded like it:

List<string> AllElements = new List<string>();
        List<Ordii> ordi = new List<Ordii>();

        DataGridViewComboBoxColumn column = new DataGridViewComboBoxColumn();
        Ordii o = new Ordii();
        o.LstRef = new List<string>();

        if (CngCMBX.SelectedIndex > -1)
        {
            string filePath0 = "ali.csv";
            StreamReader monStreamReader0 = new StreamReader(filePath0);
            string ligne0 = monStreamReader0.ReadLine();
            while (ligne0 != null)
            {
                string[] temp0 = ligne0.Split(';');
                if (temp0[6] != null && temp0[1] != "")
                {
                    string[] temp = CngCMBX.SelectedItem.ToString().Split(';');
                    if (temp0[5] == temp[0] && temp0[6].Remove(10) == temp[1])
                    {
                        o = new Ordii("192.168.98.1", "Name: " + temp0[0], "Prepro", "1", "");
                        ordi.Add(o);
                        AllElements.Add(temp0[0]);
                    }
                }
                ligne0 = monStreamReader0.ReadLine();
            }
            monStreamReader0.Close();
        }
        else
            System.Windows.MessageBox.Show("First please select your Congress");

        CMBXREF.ItemsSource = AllElements;
        da.ItemsSource = ordi;

...and I've this class:

public class Ordii 
{
    public string Ip;
    public string Ref_OSS;
    public string Name;
    public string Quntity;
    public string Comments;
    public List<string> LstRef;
    public string IP { get { return this.Ip; } set { Ip = value; } }
    public string REF_OSS { get { return this.Ref_OSS; } set { Ref_OSS = value; } }
    public string NAME { get { return this.Name; } set { Name = value; } }
    public string QUNTITY { get { return this.Quntity; } set { Quntity = value; } }
    public string COMMENT { get { return this.Comments; } set { Comments = value; } }
    public List<string> LSTREF { get { return this.LstRef; } set { LstRef = value; } }
    public Ordii(string a, string b, string c, string d, string e)
    {   this.Ip = a; this.Ref_OSS = b; this.Name = c; this.Quntity = d; this.Comments = e; }
    public Ordii() { this.LstRef = new List<string>(); }
}

Please help me, tnx..

  • 1
    Not enough info, provide the XAML of your binding and also any code that might be related... It's also sometimes problematic binding potentially changing data to a List, many people use ObservableCollection instead. – learningcs Oct 26 '14 at 23:27
  • i've added the details of my code – Aliréza Rtbd Oct 27 '14 at 07:20
  • What happens in your `da_SelectionChanged` method? Are you sure it's not repopulating your grid there thus loading old combobox value? – Jerrington Oct 27 '14 at 09:42
  • Nothing, first i've tried to write sth for working, but now it's empty, what i have to write in it? – Aliréza Rtbd Oct 27 '14 at 11:00
  • at first, i read all datas by a file 'CSV' and i load theme in a combobox, by changing this combobox, the binding part will work. it means that just one time i call the method for binding the datagrid, in the DataGridTextColumn i dont have any probleme and after the changes, it will be there and editable, but when i choose the combobox and i choose sth in, and after i choose another cell in datagrid, the value that i've selected in combobox reset! just like when i didn't choose anything in it! i don't know why? i have to write a methode for changing the combobox events or ...? – Aliréza Rtbd Oct 27 '14 at 11:11
  • if you can, could u give a simple code that contains a combobox in a datagrid and it binds by a list of string?! and by changing the values in combobx it save your changes and after click on another cell the combobox not reseted! – Aliréza Rtbd Oct 27 '14 at 11:19
  • http://stackoverflow.com/questions/19003133/wpf-datagrid-combobox-column tnx myself – Aliréza Rtbd Oct 29 '14 at 10:47

0 Answers0