با سلام

دوست عزیز

مشکل مرتب شدن ردیف ها حل شد.

من یک فرم به شکل زیر درست کردم که خروجی ازش گرفتم:

MyChart.PNG

از این SP استفاده کردم:


ALTER proc [dbo].[Select_All_tblOrganizationChart]
AS
BEGIN
select ocTitle ,
SUBSTRING(REPLACE(ocLevel.ToString(), '/', ':'), 2, LEN(ocLevel.ToString())-2) as b,
REPLICATE('>', ocLevel.GetLevel()-1)
from tbl_OrganizationChart
ORDER BY b ASC;
END


و کدهایی که خروجی SP را در TreeView قرار می دهند:


private DataTable Select_All_tblOrganizationChart()
{
SqlDataAdapter da = new SqlDataAdapter("Select_All_tblOrganizationChart", cDatabase.myConn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
DataTable dt = new DataTable();


try
{
cDatabase.OpenConnection();
da.Fill(dt);
//dgv_ListVacationType.DataSource = dt;
cDatabase.CloseConnection();
return dt;
}
catch (Exception ex)
{
cDatabase.CloseConnection();
MessageBox.Show(".خطایی در ارتباط با پایگاه داده ها رخ داده است" + "\n\n" + ".امکان بدست آوردن لیست انواع استخدام وجود ندارد" + "\n\n" + "خطای فنی :" + "\n\n" + ex.Message);
return null;
}
}


private void ConvertDataTable_To_TreeView(DataTable dt)
{
string str = "";
string pre = "";
TreeNode node = null;
foreach (DataRow row in dt.Rows)
{
str = row[2].ToString();
if (str == "")
{
node = tvChart.Nodes.Add(row[0].ToString());
pre = row[2].ToString();
}
else
{
if (row[2].ToString().Length < pre.Length)
{
int count = pre.Length - row[2].ToString().Length;
for (int i = 0; i < count; i++)
{
node = node.Parent.Parent;
}
pre = row[2].ToString();


node = node.Nodes.Add(row[0].ToString());
}
else if (row[2].ToString().Length == pre.Length)
{
pre = row[2].ToString();


if (node.Parent!=null)
{
node = node.Parent.Nodes.Add(row[0].ToString());
}
else
{
node.Nodes.Add(row[0].ToString());
}



}
else
{
pre = row[2].ToString();
node = node.Nodes.Add(row[0].ToString());
}
}


}
}


================================================== ======

لطفا یک بررسی بکنید ببیند خوبه یا نه.

همچنین اگر کدم مشکل داره بهم بگید.

================================================== ======

حالا باید بریم سراغ حذف و اضافه . . .

با تشکر