当前位置:编程学习 > C#/ASP.NET >>

错误提示:排序字符串包含一个不在 IBindingList 中的属性。

调试过得去,但是点了窗体里面的按钮就出现这样的错误:排序字符串包含一个不在 IBindingList 中的属性。

相关代码如下:
private void FormSortFilter_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“myDatabaseDataSet.MyTable2”中。您可以根据需要移动或移除它。
            this.myTable2TableAdapter.Fill(this.myDatabaseDataSet.MyTable2);
            FillFieldToComboBox(ref comboBoxSortFileld);
            comboBoxFilterFileld .Items.AddRange(new object[] { "姓名", "成绩" });
            comboBoxOperator .Items.AddRange (new object []{">","<","="});
        }
        private void FillFieldToComboBox(ref ComboBox combobox)
        {
            combobox.Items.Clear();
            for (int i = 0; i < myDatabaseDataSet.MyTable2.Columns.Count; i++)
            {
                combobox.Items.Add(myDatabaseDataSet.MyTable2.Columns[i].ColumnName);
            }
        }
        private void ShowSortString()
        {
            textBoxSortString .Text ="";
            for(int i=0;i<listBoxSort .Items .Count ;i++)
            {
                string item = listBoxSort.Items[i].ToString().Replace("(升序)", "ASC");
                item =item .Replace ("(降序)","DESC");
                textBoxSortString .Text +=","+item ;
            }
            if(textBoxSortString .Text .Length >0)
            {
                textBoxSortString .Text =textBoxSortString .Text .Remove (0,1);
            }

        }
 
private void MoveUp(ref ListBox listbox)
        {
            int index = listbox.SelectedIndex;
            if (index > 0)
            {
                object item = listbox.Items[index];
                listbox.Items[index] = listbox.Items[index - 1];
                listbox.Items[index - 1] = item;
                listbox.SelectedIndex = index - 1;
            }
        }
        private void MoveDown(ref ListBox listbox)
        {
            int index = listbox.SelectedIndex;
            if (index < listbox.Items.Count - 1)
            {
                object item = listbox.Items[index];
                listbox.Items[index] = listbox.Items[index + 1];
                listbox.Items[index + 1] = item;
                listbox.SelectedIndex = index + 1;
            }
        }

        private void buttonAddSort_Click(object sender, EventArgs e)
        {
            if (comboBoxSortFileld.SelectedIndex == -1)
            {
                MessageBox.Show("请选择要排序的列");
            }
            else
            {
                string item1 = comboBoxSortFileld.SelectedIndex.ToString() + "(升序)";
                string item2 = comboBoxSortFileld.SelectedIndex.ToString() + "(降序)";
                if (listBoxSort.Items.Contains(item1) == false &&
                    listBoxSort.Items.Contains(item2) == false)
                {
                    string sortTypeString = (radioButtonAsc.Checked ? "(升序)" : "(降序)");
                    listBoxSort.Items.Add(comboBoxSortFileld.SelectedItem.ToString() + sortTypeString);
                    ShowSortString();
                }
                else
                {
                    MessageBox.Show("排序项目已包含该列");
                }
            }
        
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (listBoxSort.SelectedIndex != -1)
            {
                listBoxSort.Items.Remove(listBoxSort.SelectedItem);
                ShowSortString();

            }
        }

        private void buttonSortMoveUp_Click(object sender, EventArgs e)
        {
            MoveUp(ref listBoxSort);
            ShowSortString();
        }

        private void buttonMoveDown_Click(object sender, EventArgs e)
        {
            MoveDown(ref listBoxSort);
            ShowSortString();

        }

        private void buttonSetSort_Click(object sender, EventArgs e)
        {
            if (textBoxSortString.Text.Length > 0)
            {
                myTable2BindingSource.Sort = textBoxSortString.Text;//出错位置
            }
        }


 麻烦各位高手帮忙,先在这里感谢了。。。
--------------------编程问答-------------------- 自己顶一下,路过请不要错过~~ --------------------编程问答-------------------- 怎么没人??帮帮忙啊!! --------------------编程问答-------------------- private   void   ShowSortString() 
                { 
                        textBoxSortString   .Text   = " "; 
                        for(int   i=0;i <listBoxSort   .Items   .Count   ;i++) 
                        { 
                                string   item   =   listBoxSort.Items[i].ToString().Replace( "(升序) ",   "ASC "); //ASC的前面要有空格的

                                item   =item   .Replace   ( "(降序) ", "DESC "); //DESC的前面要有空格的                                textBoxSortString   .Text   += ", "+item   ; 
                        } 
                        if(textBoxSortString   .Text   .Length   > 0) 
                        { 
                                textBoxSortString   .Text   =textBoxSortString   .Text   .Remove   (0,1); 
                        } 

                } 
--------------------编程问答-------------------- 我也遇到同样的问题了,无法搞定,没人解答吗?
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,