【发布时间】:2020-02-26 20:59:20
【问题描述】:
我也收到了这个错误
附加信息:无效表达式:[发票日期] = '01 / 11/2020 04:16:02 p.m. '
当按日期过滤其他过滤器不是日期的过滤器时,这就是我用来将过滤器放在 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所做的,我放的第一个使过滤器出现并进行过滤的代码
-
或者你有什么推荐的?我是否需要过滤器才能工作,还有其他选择吗?
标签: c# winforms filter datagridview