/// <summary>
/// Remove the unwanted space in filtering dataTable
/// </summary>
/// <param
name="datable"></param>
private void ClearSpace(DataTable datable)
{
List<List<object>> listTemp = new List<List<object>>();
for (int i = 0; i < datable.Columns.Count; i++)
{
List<object> stack = new List<object>();
for (int j = 0; j < datable.Rows.Count; j++)
{
object obj =
datable.Rows[j][i];
if (obj.ToString() != "")
{
stack.Add(obj);
}
}
listTemp.Add(stack);
}
datable.Clear();
while (hasData(listTemp) == true)
{
for (int i = 0; i < datable.Columns.Count; i++)
{
DataRow dr =
datable.NewRow();
for (int j = 0; j <
listTemp.Count; j++)
{
if (listTemp[j].Count != 0)
{
dr[j] =
listTemp[j][0];
listTemp[j].RemoveAt(0);
}
}
datable.Rows.Add(dr);
}
}
}
/// <summary>
/// Delete the empty row from the table
/// </summary>
/// <param
name="dt"></param>
public static void RemoveNullColumnFromDataTable(DataTable dt)
{
for (int i = dt.Rows.Count - 1; i >= 0; i--)
{
if (dt.Rows[i][1] == DBNull.Value)
dt.Rows[i].Delete();
}
dt.AcceptChanges();
}
/// <summary>
/// temp data
/// </summary>
/// <param
name="listTemp"></param>
/// <returns></returns>
private bool hasData(List<List<object>> listTemp)
{
foreach (var item in listTemp)
{
if (item.Count != 0)
{
return true;
}
}
return false;
}
No comments:
Post a Comment