2017-05-14 134 views
-5

過濾數據表列爲了給null或空白過濾數據表列我用這個過濾器,但它不到風度工作如何爲空或空白

dt.DefaultView.RowFilter = 
string.Format("[{0}] ='%{1}%'(string.IsNullOrWhiteSpace(dt.Columns[int.Parse(comboBox8.Text) - 1].ColumnName.ToString())),true); 
+0

爲什麼不是dt = dt.AsEnumerable()。其中​​(x => x.Field [0]!= null).CopyToDataTable(); – jdweng

+0

sory it dosn't work我需要編輯上面的過濾器來過濾列或名稱爲空的空白dt.Columns [int.Parse(comboBox8.Text) - 1 – alhussein

+0

您可以使用列名而不是索引:dt = dt .AsEnumerable()。Where(x =>(x.Field [comboBox8.Text]!= null) ||!string.IsNullOrWhiteSpace(x.Field ([comboBox8.Text]))。CopyToDataTable(); – jdweng

回答

0

我通過解決這個問題: 1 - 使用這個有趣

public static bool IsNullOrWhiteSpace(string value) 
    { 
     if (value != null) 
     { 
      for (int i = 0; i < value.Length; i++) 
      { 
       if (!char.IsWhiteSpace(value[i])) 
       { 
        return false; 
       } 
      } 
     } 
     return true; 
    } 

然後我使用特定列這個代碼在數據網格視圖: 如果((function.IsNullOrWhiteSpace(dataGridView3.Rows [j]的.Cells [int.Parse(comboBox8.Text) - 1] .Value.ToString())== true)) dataGridView3.Rows [j] .Cells [int.Parse (comboBox8.Text) - 1] .Value =「Empty」; (「[{0}]不是LIKE'%{1}%'」,dt.Columns [int.Parse(comboBox8.Text))。 - 1] .ColumnName,「Empty」);