c# - GridView DevExpress 检查是否有任何单元格为空

标签 c# devexpress

enter image description here

我需要检查单元格是否为空并存储一条消息,然后在包含所有消息的每一行中创建一个新单元格

但我不知道如何使用 DevExpress,有人可以帮助我编写代码吗

    string Name = "First Name";
    string FName = "Father Name";
    string LName = "Last Name";
    string EmpCode = "Employee Code";
    string Tax = "Tax#";
    string SocSec = "Soc.Sec#";
    string EmpType = "Employment Type";
    string DepCode = "Department Code";
    string DepDesc = "Department Description";
    private void simpleButton1_Click(object sender, System.EventArgs e)
    {
        try
        {
            OleDbConnection con = new OleDbConnection();
            con.ConnectionString = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=C:\\Users\\pc\\Documents\\Emp.xlsx;Extended Properties=\"Excel 12.0;HDR=Yes\"";

            con.Open();
            DataTable dtSchema;
            dtSchema = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
            OleDbCommand Command = new OleDbCommand ("select * FROM [" + dtSchema.Rows[0]["TABLE_NAME"].ToString() + "]", con);
            OleDbDataAdapter da = new OleDbDataAdapter(Command);
            DataSet ds = new DataSet ();
            da.Fill(ds);
            dataGrid1.DataSource = ds.Tables[0];
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

这个循环没有给我关于空单元格的正确信息我认为我写的是不正确的也许还有另一种更好的方法......

        for (int rows = 0 ; rows < gridView3.RowCount ; rows ++)
        {
            string[] msg = new string[50];

            if ((gridView3.GetRowCellValue(rows, gridView3.Columns["LName"])) == null)
            {
                msg[rows] = "name missing";
            }
        }

最佳答案

据我所知,单元格的值不会为空。然而,底层数据源将具有空值。

检查单元格的数据是否为空或从空值求和:

private bool IsNullValue(PivotDrillDownDataSource ds, PivotGridField field)
{
    if (ds.RowCount == 0 || field == null) return false;
    for (int i = 0; i < ds.RowCount; i++)
    {
        if (Equals(ds[i][field], null))
        return true;
    }
    return false;
 } 

要更改空单元格中的文本:

if (IsNullValue(e.CreateDrillDownDataSource(), e.DataField))
     e.DisplayText = "NULL OR SUM WITH NULL";

关于c# - GridView DevExpress 检查是否有任何单元格为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14559707/

相关文章:

c# - for-loop 以覆盖基于步进符号增加/减少的范围

c# - 在 C# 中修改现有的 XML 内容

c# - 在 Avalon Dock 中,如何以编程方式隐藏 LayoutDocumentPane 项目并恢复它们

c# - 在 DevExpress PivotGridControl 中使用 DisplayNameAttribute

c# - 安全地抛出在另一个线程上创建的异常 C#

c# - 为什么使用 {} 而不是加号打印出来?

c# - Asp.Net SQL删除语句

c# - 为什么我不能编辑 DevExpress 数据透视表数据?

vb.net - Devexpress Gridview editform如何在中间打开?

c# - 将 List<object> 转换为 List<myclass> c#