c# - 为什么在 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 的日期之前,既没有时间,也没有时间,只有日期,这是一个问题。
另一个是当你点击过滤器时会出现一些中文字母或者我不知道在哪里
在第一个选项中,如果我点击它,会出现一盒更高级的过滤内容,但一切都是中文的,或者我不知道是什么语言,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 的分钟和秒,但它也没有工作
推荐阅读
- javascript - 如何做多级选择字段?
- flutter - Dart:无法转换列表
列出 - python - 如何通过按列中的值切片来创建多个数据框,如列表?
- python - 根据 Beautiful Soup/Python 中的条件返回表信息
- python - 如何在 python 中使用 groupby 对多个条件进行求和?
- c - 错误:“字符串”之前的预期表达式和函数“strcmp”的参数太少
- assembly - 在程序中使用它们之前的汇编寄存器中有什么?
- python - Pandas df.equals() 在相同的数据帧上返回 False?
- python - 如何在 python 中开发一种算法来从 numpy 数组中的值中生成特定的对
- php - 获取 OAuth2 访问令牌后获取 Yahoo 用户信息