[quote="EvgenyT"]William,
As you can see from demos, there's Postback button to demonstrate that treeview keeps all its nodes between postbacks.
How do you populate treeview? Any code appreciated.
Here is some code that populates the Tree:
///
/// Extracts database data from an SQLDataReader.
/// Displays information for the SqlStatements.SQLStatement18 command
///
private void DisplayStatement12(SqlDataReader reader, bool bOutputData)
{
int prev_word_id = -1;
int word_id = -1;
int timestamp_id = -1;
short prev_movie_id = -1;
short movie_id = 1;
string output = null;
string url = null;
string text = null;
FlyTreeNode treeNode = new FlyTreeNode();
FlyTreeNode treeNode2 = new FlyTreeNode();
FlyTreeNode treeNode3 = new FlyTreeNode();
ArrayList tempResultList = new ArrayList();
try
{
if (reader.HasRows)
{
if (dataSet2 == null)
{
dataSet2 = new DVDSearchDataSet();
}
}
else
{
return;
}
//no result TreeNode added in ProcessSQLStatement
while (reader.Read())
{
object[] formatParams = new object[5];
formatParams[0] = reader.GetInt16(0); //movie_id
formatParams[1] = reader.GetString(1); //text
formatParams[2] = reader.GetString(2); //url
formatParams[3] = reader.GetInt32(3); //word_id
formatParams[4] = reader.GetInt32(4); //timestamp_id - used for GetHashCode() method
movie_id = (short)formatParams[0];
text = (string)formatParams[1];
url = (string)formatParams[2];
word_id = (int)formatParams[3];
timestamp_id = (int)formatParams[4];
// Create DVDQueryInfo object
DVDQueryInfo dvdQueryInfo = new DVDQueryInfo(
movie_id,
word_id,
-1,
-1,
timestamp_id,
text,
url);
// Do not process duplicates.
// Add in reverse order.
if (!tempResultList.Contains(dvdQueryInfo))
{
// Add row to DVDSearchDataSet
dataSet2.AddRow(
movie_id,
word_id,
-1,
-1,
timestamp_id,
text,
url);
tempResultList.Insert(0, dvdQueryInfo);
}
if (bCreateTreeNodes)
{
// If new word
if (prev_word_id == -1 || prev_word_id != word_id)
{
treeNode = new FlyTreeNode();
object[] formatParams3 = new object[1];
formatParams3[0] = (string)dvdWordHash[word_id];
treeNode.Text = string.Format("\"{0}\"", formatParams3);
treeNode.ToolTip = "This is the DVD search word.";
rootNode.ChildNodes.Add(treeNode);
prev_word_id = word_id;
}
// If new movie
if (prev_movie_id == -1 || prev_movie_id != movie_id)
{
// Add movie title tree node
treeNode2 = new FlyTreeNode();
treeNode2.Text = (string)dvdTitles[(int)movie_id];
treeNode2.ToolTip = "This is a DVD title.";
treeNode.ChildNodes.Add(treeNode2);
prev_movie_id = movie_id;
}
text = string.Format("\"{0}\"", text);
treeNode3 = new FlyTreeNode();
treeNode3.Text = text;
treeNode3.ToolTip = "Double-click to view the video clip.";
treeNode3.NavigateUrl = CreateMoviePlayerURL(url);
treeNode2.ChildNodes.Add(treeNode3);
}
DVDResultCount++;
}
//add temp list (in insert order) to stack
foreach (DVDQueryInfo dvdQueryInfo2 in tempResultList)
{
//do not include/display duplicates
if (!results.Contains((object)dvdQueryInfo2))
{
//push onto stack here
results.Push(dvdQueryInfo2);
}
}
}
catch (InvalidCastException ice)
{
output += "\n" + ice.Message + "\n";
if (appendText != null)
{
appendText(output);
}
}
catch (Exception e)
{
output += "\n" + e.Message + "\n";
if (appendText != null)
{
appendText(output);
}
}
}
I am fairly certain that the populate code is correct. The rootNode variable is added prior to function invocation.
Again, I am passing my FlyTreeView object not by reference, and to a static variable. This is probably the error.
Reason being is that I cannot pass the ViewState Property by reference.
Thanks,
William Johnston