English 中文(简体)
参考数据 添加新的记录
原标题:DevExpress DataBinding, Add new Record

我在双赢申请中使用DevExpress,我有电网格、数据输入表、数据分析器、所有数据集。

我想添加新的记录,如果使用数据分析器“Add”这一记录是好的,那么如何使用“New Records,纽顿?

BindingSource.AddNew() 

它通常不工作,而是以不工作为主。

最佳回答

如果你想要使用约束性,那么就会使用具有约束性来源的物体。

and use the binding list .AddingNew += new AddingNewEventHandler(listOfParts_AddingNew); event to add new entity object ..

See the example of BledList on MSDN

void listOfParts_AddingNew(object sender, AddingNewEventArgs e)
        {
            e.NewObject = new Part(textBox1.Text, int.Parse(textBox2.Text));

        }

DevExpress WinForm Controls与分类数据来源等相比,以具有约束力的来源迅速开展工作。 YOu利用这些例子执行具有约束力的文书。

set gridview and the associcated controls datasource to bindsouce that you have created... process your form with the this MSDN example..

也许你们会从这个意义上得到一些想法。

private void BindingLIstDemo_Load(object sender, EventArgs e)
        {
            InitializeListOfEmployees();
            BindlstEmp();
            listofEmp.AddingNew += new AddingNewEventHandler(listOfEmp_AddingNew);
            listofEmp.ListChanged += new ListChangedEventHandler(listofEmp_ListChanged);

        }

        private void BindlstEmp()
        {
            lstEmpList.Items.Clear();
            lstEmpList.DataSource = listofEmp;
            lstEmpList.DisplayMember = "Name";

        }

        void listofEmp_ListChanged(object sender, ListChangedEventArgs e)
        {
            MessageBox.Show(e.ListChangedType.ToString());
                //throw new NotImplementedException();
        }

        //declare list of employees
        BindingList<Emp> listofEmp;
        private void InitializeListOfEmployees()
        {

            //throw new NotImplementedException();
            // Create the new BindingList of Employees.
            listofEmp = new BindingList<Emp>();

            // Allow new Employee to be added, but not removed once committed.
            listofEmp.AllowNew = true;
            listofEmp.AllowRemove = true;

            // Raise ListChanged events when new Employees are added.
            listofEmp.RaiseListChangedEvents = true;

            // Do not allow Employee to be edited.
            listofEmp.AllowEdit = false;

            listofEmp.Add(new Emp(1, "Niranjan", 10000));
            listofEmp .Add (new Emp (2,"Jai", 8000));

          }


        // Create a new Employee from the text in the two text boxes.
        void listOfEmp_AddingNew(object sender, AddingNewEventArgs e)
        {
            e.NewObject = new Emp (Convert.ToInt32(txtId.Text), txtName.Text,Convert.ToInt32(txtSalary.Text));

        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            Emp empItem = listofEmp.AddNew();
            txtId.Text = txtName.Text = txtSalary.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form1 obj = new Form1();
            obj.Show();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            var sg = (from sc in listofEmp.ToList<Emp>() where sc.Name == ((Emp)lstEmpList.SelectedValue).Name select sc);





        }

        private void lstEmpList_SelectedIndexChanged(object sender, EventArgs e)
        {
            Emp se = listofEmp[lstEmpList.SelectedIndex];
            txtId.Text = se.Id.ToString();
            txtName.Text = se.Name;
            txtSalary.Text = se.Salary.ToString();

        }

此处我使用<条码>BindingList作为数据来源<条码>BindingList<Emp> 名单 就业;和列入记录网的网址载于清单箱控制中,但与你的电网格一样。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签