Welcome to the Xceed Community Sign in | Join | Help
Community Search  

insert row with C#

Sort Posts: Previous Next
  •  06-06-2008, 11:21 AM Post no. 12756

    insert row with C#

    Hello 

    can u explain me how i can insert rows by programming with C#?

    my xaml:

    <my:DataGridControl Height="160" Name="dataGridControl1" Width="280" EditTriggers="ClickOnCurrentCell" ValidationMode="RowEndingEdit">
            <my:DataGridControl.Columns>
                <my:Column FieldName="info" Title="Info" IsMainColumn="True" />
                <my:Column FieldName="produktname" Title="Produktname" />
                <my:Column FieldName="einheitspreis" Title="Einheitspreis" />
                <my:Column FieldName="organisch" Title="Organisch" />
                <my:Column FieldName="datum" Title="Datum" />
                <my:Column FieldName="anzahl" Title="Anzahl" />
            </my:DataGridControl.Columns>
        </my:DataGridControl>

     

    C#

     public partial class Window1 : Window
        {
            public Window1()
            {
                InitializeComponent();
                ProvideData();
            }


            private void ProvideData()
            {
                ObservableCollection<DataObject> source = new ObservableCollection<DataObject>();
                int wieOft = 1000;
                for (int i = 1; i <= wieOft; i++)
                {
                    string str = "info " + Convert.ToString(i);
                    source.Add(new DataObject(str));
                }      
                dataGridControl1.ItemsSource = source;

               
            }

    ...

    }
     

     

    with this code rowqs are inserted but a dont see any e text ?

    and i cant edit the cells why?

    how can i fill the grid by my own in unbound mode the help file is wortless for this! 

     

    regards rene 

  •  06-06-2008, 12:32 PM Post no. 12757 in reply to 12756

    Re: insert row with C#

    Take a look at the Providing Unbound Data example in the Providing Data  topic. 

    From the same topic:

    The DataGridCollectionView supports insertion as long as the underlying DataGridCollectionView-wrapped collection implements the IBindingList interface (you can also use BindingList<>) and its AllowNew property returns true. In this case, the AddNew method can be used to add new data items to the underlying collection, while the EndNew and CancelNew methods can be used to commit the new item or cancel its addition.

    As for being able to edit, are the properties in your data object get/set? Ifyou provide your data after the Window has loaded, do you see your data?


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
    Filed under:
  •  06-06-2008, 4:30 PM Post no. 12771 in reply to 12757

    Re: insert row with C#

    solved


    in Windows1.xaml.cs

    namespace xceed2
    {
        /// <summary>
        /// Interaktionslogik für Window1.xaml
        /// </summary>
        public partial class Window1 : Window
        {
            public Window1()
            {
                InitializeComponent();
                this.FlowDirection = FlowDirection.RightToLeft;
                ProvideData();
            }

            private void ProvideData()
            {
                DataGridControl control = new DataGridControl();
                this.Content = control;
                control.ItemsSource = new NameList();
                control.FlowDirection = FlowDirection.RightToLeft;
                //grid.ItemsSource = new NameList();        // wenns vom xaml kommt
            }
        }
    }

     

    own Namelist.cs file

     

    using System;
    using System.Collections;
    using System.Collections.ObjectModel;       //fuer ObservableCollection

    namespace xceed_data
    {
        public class NameList : ObservableCollection<PersonName>
        {
            public NameList()
                : base()
            {
                Add(new PersonName("Willa", "Cather", true, "Zwei"));
                Add(new PersonName("Isak", "Dinesen", false, "Zwei"));
                Add(new PersonName("Victor", "Hugo", true, "Zwei"));
                Add(new PersonName("Jules", "Verne", false, "Zwei"));
               
            }
           
        }
       
        public class PersonName
        {
            private string firstName;
            private string lastName;
            private bool bCheckB;
            private string cdstring;


            public PersonName(string first, string last, bool bcheckb, string cd)
            {
                this.firstName = first;
                this.lastName = last;
                this.bCheckB = bcheckb;
                this.cdstring = cd;
            }       

            public string FirstName
            {
                get { return firstName; }
                set { firstName = value; }
            }

            public string LastName
            {
                get { return lastName; }
                set { lastName = value; }
            }

            public bool CheckB
            {
                get { return bCheckB; }
                set { bCheckB = value; }
            }

            public string CDString
            {
                get { return cdstring; }
                set { cdstring = value; }
            }
        }
    }

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.