繁体   English   中英

为什么在 datagridview 的列中按日期过滤时会出现错误? 'System.NotSupportedException' DataGridViewAutoFilter.dll

[英]Why do I get an error when filtering by date in a column of the datagridview? 'System.NotSupportedException' DataGridViewAutoFilter.dll

我得到了这个错误

附加信息:无效表达式:[发票日期] = '01 / 11/2020 04:16:02 pm '

当按日期过滤不是过滤器工作日期的其他过滤器时,这就是我用来将过滤器放在 datagridview 中的方法:

BindingSource bs = new BindingSource();
                    bs.DataSource = oDsHDRCelMousClic.Tables[0];
                    oDsHDRCelMousClic.BeginInit();
                    grdDET.DataSource = bs;
                    foreach (DataGridViewColumn item in grdDET.Columns)
                    {
                        item.HeaderCell = new DataGridViewAutoFilterColumnHeaderCell(item.HeaderCell);

                    }

我想这是日期格式,但我该如何更改它? 我认为这是从 bd 带来的,因为在用户选择 datetimepicker 的日期之前,没有时间既不是 am 也 pm 只是日期,这是一个问题。

另一个是当你点击过滤器时会出现一些中文字母或者我不知道在哪里

中国符号

在第一个选项中,如果我点击它,会出现一盒更高级的过滤内容,但所有内容都是中文或我不知道什么语言,dll将从这里下载https://www.nuget。 org/packages/DataGridViewAutoFilter/1.0 .0 我想有问题

中国符号

第三个问题是,通过单击每列的标题对数据进行排序,左侧的前 2 列运行良好,在第 5 列中也可以正常工作,但在其他列中,如果我单击它,则会对它们进行排序,但它执行我所拥有的右侧的 CFD 按钮,这是您单击按钮时的代码

private void grdDET_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    //if (grdDET.Columns["CFD"].DisplayIndex == 8 || grdDET.Columns["Aperak"].DisplayIndex == 9)
    //{

        try
        {
            String Ruta = String.Empty;
            String nombre_xml = String.Empty;
            String strXML = String.Empty;
            String Id_Cnsc_CFD = String.Empty;
            //DataSet oDs = new DataSet();
            String CadenaConexion = String.Empty;

            #region Leemos Archivo de Configuración
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

            XmlNode appSettingsNode =
              xmlDoc.SelectSingleNode("configuration/userSettings/rutas");

            if (appSettingsNode != null)
            {
                foreach (XmlNode node in appSettingsNode.ChildNodes)
                {
                    string value = node.Attributes["value"].Value.ToString();
                    string keyName = node.Attributes["key"].Value.ToString();

                    if (keyName == "RutaArchivo")
                        Ruta = value;
                }

                if (false == Ruta.EndsWith("\\"))
                {
                    Ruta += '\\';
                }

                if (Directory.Exists(Ruta) == false)
                {
                    throw new Exception("No se encontró el directorio \"" + Ruta + "\".");
                }

                foreach (String xmls in Directory.GetFiles(Ruta))
                {
                    FileInfo fi = new FileInfo(xmls);

                    if (fi.Extension.ToUpper() == ".XML")
                    {
                        File.Delete(fi.FullName);
                    }
                }
            }
            else
            {
                throw new Exception("No se encontró el nodo \"rutas\".");
            }
            #endregion

            //if (e.RowIndex >= 0)
            //{
            //    DataGridViewRow row = grdHDR.Rows[e.RowIndex];
            //    grdDET.Text = row.Cells[0].Value.ToString();
            //    //txt3_prov.Text = row.Cells[4].Value.ToString();
            //Id_Cnsc_CFD = e.ColumnIndex.Equals("Id_Cnsc_CFD").ToString().Trim();
            //}

            Id_Cnsc_CFD = grdDET.CurrentRow.Cells["Id_Cnsc_CFD"].Value.ToString().Trim();

            try
            {
                sp = db.GetStoredProcCommand("eDocResumenEmisor_pUP");

                db.AddInParameter(sp, "@pCveOperacion", DbType.String, "X");
                db.AddInParameter(sp, "@pId_Cnsc_CFD", DbType.Int32, Id_Cnsc_CFD);

                oDsDET = db.ExecuteDataSet(sp);

            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (oDsDET.Tables.Count == 1)
            {
                if (oDsDET.Tables[0].Rows.Count == 1)
                {
                    if (grdDET.CurrentCell.Value.ToString().Trim() == "CFD")
                    {
                        strXML = oDsDET.Tables[0].Rows[0]["XML"].ToString().Trim();
                    }
                    else if (grdDET.CurrentRow.Cells["Aperak"].Value.ToString().Trim() == "Aperak")
                    {
                        strXML = oDsDET.Tables[0].Rows[0]["Aperak"].ToString().Trim();
                    }
                    //if (grdDET.SelectedCells.Count > 0)
                    //{
                    //    int selectedrowindex = grdDET.SelectedCells[0].RowIndex;
                    //    DataGridViewRow selectedRow = grdDET.Rows[selectedrowindex];
                    //    string a = Convert.ToString(selectedRow.Cells["CFD"].Value);
                    //}
                    //if (a == "CFD")
                    //{
                    //    strXML = oDs.Tables[0].Rows[0]["XML"].ToString().Trim();
                    //}
                    //if (a == "Aperak")
                    //{
                    //    strXML = oDs.Tables[0].Rows[0]["Aperak"].ToString().Trim();
                    //}
                }
            }

            nombre_xml = System.Guid.NewGuid() + ".XML";

            //Creamos el Archivo APERAK del error...
            using (System.IO.FileStream fs = System.IO.File.Create(Ruta + nombre_xml, 1024))
            {
                // Add some information to the file.
                byte[] info = new System.Text.UTF8Encoding(true).GetBytes(strXML);
                fs.Write(info, 0, info.Length);
            }

            Process.Start(Ruta + nombre_xml);

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    //}

}

PD 我是 Windows 窗体的新手

好吧,事实证明我更新或更改了 dll 并且它不再向我显示中文符号并不断向我发送错误但现在在另一个类 DataGridViewAutoFilterColumnHeaderCell.cs 我想这是你说的代码@jfiggins

 private void UpdateFilter()
    {
        // Continue only if the selection has changed.
        if (dropDownListBox.SelectedItem.ToString().Equals(selectedFilterValue))
        {
            return;
        }

        // Store the new selection value. 
        selectedFilterValue = dropDownListBox.SelectedItem.ToString();

        // Cast the data source to an IBindingListView.
        IBindingListView data = 
            this.DataGridView.DataSource as IBindingListView;

        Debug.Assert(data != null && data.SupportsFiltering,
            "DataSource is not an IBindingListView or does not support filtering");

        // If the user selection is (All), remove any filter currently 
        // in effect for the column. 
        if (selectedFilterValue.Equals("(All)"))
        {
            data.Filter = FilterWithoutCurrentColumn(data.Filter);
            filtered = false;
            currentColumnFilter = String.Empty;
            return;
        }

        // Declare a variable to store the filter string for this column.
        String newColumnFilter = null;

        // Store the column name in a form acceptable to the Filter property, 
        // using a backslash to escape any closing square brackets. 
        String columnProperty = 
            OwningColumn.DataPropertyName.Replace("]", @"\]");

        // Determine the column filter string based on the user selection.
        // For (Blanks) and (NonBlanks), the filter string determines whether
        // the column value is null or an empty string. Otherwise, the filter
        // string determines whether the column value is the selected value. 
        switch (selectedFilterValue)
        {
            case "(Blanks)":
                newColumnFilter = String.Format(
                    "LEN(ISNULL(CONVERT([{0}],'System.String'),''))=0",
                    columnProperty);
                break;
            case "(NonBlanks)":
                newColumnFilter = String.Format(
                    "LEN(ISNULL(CONVERT([{0}],'System.String'),''))>0",
                    columnProperty);
                break;
            default:
                newColumnFilter = String.Format("[{0}]='{1}'",
                    columnProperty,
                    ((String)filters[selectedFilterValue])
                    .Replace("'", "''"));  
                break;
        }

        // Determine the new filter string by removing the previous column 
        // filter string from the BindingSource.Filter value, then appending 
        // the new column filter string, using " AND " as appropriate. 
        String newFilter = FilterWithoutCurrentColumn(data.Filter);
        if (String.IsNullOrEmpty(newFilter))
        {
            newFilter += newColumnFilter;
        }
        else
        {
            newFilter += " AND " + newColumnFilter;
        }


        // Set the filter to the new value.
        try
        {
            data.Filter = newFilter;
        }
        catch (InvalidExpressionException ex)
        {
            throw new NotSupportedException(
                "Invalid expression: " + newFilter, ex);
        }

        // Indicate that the column is currently filtered
        // and store the new column filter for use by subsequent
        // calls to the FilterWithoutCurrentColumn method. 
        filtered = true;
        currentColumnFilter = newColumnFilter;
    }

在这里我现在得到那个错误

错误

我没有做 sp 但带来了这个:

SELECT  

@Fec_Ini = CONVERT(DATETIME, CONVERT(VARCHAR(20), @pFec_Ini, 112) + '00:00:00')
,@Fec_Fin = CONVERT(DATETIME, CONVERT(VARCHAR(20), @pFec_Fin, 112) + '23:59:00')

我尝试删除 sp 的分钟和秒,但它也不起作用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM