Question:
How do i bind multiple Nodes in RadTreeView
This is my code:
if (lblCategory != null && lblCategory.Text != string.Empty && rtCategory != null)
{
string[] tree = lblCategory.Text.Split(',');
for (int i = 0; i < tree.Length; i++)
{
foreach (RadTreeNode t in rtCategory.Nodes)
{
if (t.Value == tree[i])
{
t.Selected = true;
}
}
}
rtCategory.ExpandAllNodes();
}
if (lblCategory != null && lblCategory.Text != string.Empty && rtCategory != null)
{
string[] tree = lblCategory.Text.Split(',');
for (int i = 0; i < tree.Length; i++)
{
foreach (RadTreeNode t in rtCategory.GetAllNodes())
{
if (t.Value == tree[i])
{
t.Selected = true;
}
}
}
rtCategory.ExpandAllNodes();
}
Use GetAllNodes() instead of Node in foreach condition
Related
I know this is a dumb question because you cannot modify the loop collection while in a loop, but I do need to change it. I know I must not change the referenced objects, but I have no idea how to do this.
var orders = _orderService.GetOrders(o => !o.Deleted &&
o.OrderStatus != OrderStatus.Cancelled &&
o.OrderStatus != OrderStatus.Complete);
foreach (var order in orders)
{
if (order.PaymentStatus == PaymentStatus.Paid)
{
if (order.ShippingStatus == ShippingStatus.ShippingNotRequired || order.ShippingStatus == ShippingStatus.Delivered)
{
var tempOrder = _orderService.GetOrderById(order.Id);
SetOrderStatus(tempOrder , OrderStatus.Complete, true);
}
}
}
I always get an error.
UPDATED: I changed to this
var orders = _orderService.GetOrders(o => !o.Deleted &&
o.OrderStatus != OrderStatus.Cancelled && o.OrderStatus != OrderStatus.CompletE);
List<int> orderIndex = new List<int>();
orders.ToList().ForEach(x => orderIndex.Add(x.Id));
foreach(var index in orderIndex)
{
var order = _orderService.GetOrderById(index);
if (order.PaymentStatus == PaymentStatus.Paid)
{
if (order.ShippingStatus == ShippingStatus.ShippingNotRequired || order.ShippingStatus == ShippingStatus.Delivered)
{
SetOrderStatus(order, OrderStatus.Complete, true);
}
}
}
try
int count = orders.Count; // the length of the collect : may need a different method for different collection types.
for(int i = 0; i < count; i++)
{
var current = orders[i];
// do stuff with current.
}
use for loop instead of foreach loop
for(int i=0; i<orders.Count; i++)
{
if (orders[i].PaymentStatus == PaymentStatus.Paid)
{
if (orders[i].ShippingStatus == ShippingStatus.ShippingNotRequired || orders[i].ShippingStatus == ShippingStatus.Delivered)
{
var tempOrder = _orderService.GetOrderById(orders[i].Id);
SetOrderStatus(tempOrder , OrderStatus.Complete, true);
}
}
}
I got 2 datagrid views, First datagrid 1st col or Index 0 & the Second datagrid 1st col or Index 0.
How can i loop through a specific col in the datagridviews and look for the string values,if it matches with the list then go to a function.
My approach is not working. How can i do this?
private void b_calculate_Click(object sender, EventArgs e)
{
List<string> value = new List<String>() { "AE0", "AT1", "AT2", "AT3"};
value = new List<string>(datagridview1.Columns[0].Index);
List<string> value2 = new List<String>() { "BE0", "BT1", "BT2", "BT3"};
value2 = new List<string>(datagridview2.Columns[0].Index);
//First Combination
if((value.ToString() == "AT1" || value.ToString() == "AE0" ||
value.ToString() == "AT2")
&&
(value2.ToString() == "BT1" || value2.ToString() == "BE0"))
{
gottoFunction1();
}
//Second Combination
if((value.ToString() == "AT1" || value.ToString() == "AT2" )
&&
(value2.ToString() == "BT1" || value2.ToString() == "BT2"))
{
gottoFunction2();
}
}
Here's a routine that iterates through all available rows in both DataGridViews and does the processing shown in your method:
private void b_calculate_Click(object sender, EventArgs e)
{
for (var i = 0; i < dataGridView1.RowCount; i++)
{
if (dataGridView2.RowCount <= i)
break;
var cellFromDG1 = dataGridView1.Rows[i].Cells[0];
var cellFromDG2 = dataGridView1.Rows[i].Cells[0];
if (cellFromDG1.Value == null || cellFromDG2.Value == null)
{
// this could be the empty row that allows you to
// enter a new record
continue;
}
var value = cellFromDG1.Value.ToString();
var value2 = cellFromDG2.Value.ToString();
if ((value == "AT1" || value == "AE0" || value == "AT2") &&
(value2 == "BT1" || value2 == "BE0"))
{
gottoFunction1();
}
if ((value == "AT1" || value == "AT2") &&
(value2 == "BT1" || value2 == "BT2"))
{
gottoFunction2();
}
}
}
Is it possible to initialize table adapter rows? I have the following code I've created; refactored from duplication of control names to recursively finding controls with FindControl:
private int _category;
private int _max;
private string _queryString;
private int _pageStart;
private const int PageSize = 4;
private void PopulatePage(string s)
{
using (var projectTableAdapter = new ProjectTableAdapter())
{
_max = s == "category" ? projectTableAdapter.GetDataByCategory(_category).Count : PageSize;
double totalPages = Math.Ceiling((float) _max/PageSize);
int start = (_pageStart - 1) * PageSize;
var end = _pageStart * PageSize;
if (end > _max) end = _max;
for (int i = start; i < end; i++)
{
int tmp = i - start;
int c = tmp + 1;
var image = FindControl(string.Format("ctl00$Body$ControlImage{0}", c)) as Image;
var title = FindControl(string.Format("ctl00$Body$ControlTitle{0}", c)) as Literal;
var summary = FindControl(string.Format("ctl00$Body$ControlSummary{0}", c)) as Literal;
var link = FindControl(string.Format("ctl00$Body$ControlLink{0}", c)) as HyperLink;
var listitem = FindControl(string.Format("ctl00$Body$ControlListItem{0}", c)) as HtmlGenericControl;
switch (s)
{
case "category":
DataConnection.ProjectRow projectRowCategory =
projectTableAdapter.GetDataByCategory_Active_RankOrder(_category)[i];
if (image != null) image.ImageUrl = projectRowCategory.Image;
if (title != null) title.Text = projectRowCategory.Name;
if (summary != null) summary.Text = projectRowCategory.Summary;
if (projectRowCategory.Description.Length > 0)
{
if (link != null)
{
link.NavigateUrl = string.Format("/experience/details/?id={0}",
projectRowCategory.ProjectID);
link.Visible = true;
}
}
break;
case "random":
DataConnection.ProjectRow projectRowRandom = projectTableAdapter.GetDataByRandom()[i];
if (image != null) image.ImageUrl = projectRowRandom.Image;
if (title != null) title.Text = projectRowRandom.Name;
if (summary != null) summary.Text = projectRowRandom.Summary;
if (projectRowRandom.Description.Length > 0)
{
if (link != null)
{
link.NavigateUrl = string.Format("/experience/details/?id={0}",
projectRowRandom.ProjectID);
link.Visible = true;
}
}
break;
}
if (listitem != null) listitem.Visible = true;
}
if ((Request.QueryString["p"] == null) || (Request.QueryString["p"] == "1"))
{
if (_max < PageSize)
{
ControlPage.Text = "";
}
else
{
ControlPage.Text = "<< prev | next >>";
}
}
else
{
int next = _pageStart + 1;
int prev = _pageStart - 1;
if (next > totalPages)
{
ControlPage.Text = string.Format(#"<< prev | next >></a>",
_queryString, prev);
}
else
{
ControlPage.Text =
string.Format(
#"<< prev | next >>",
_queryString, prev, next);
}
}
}
}
I want to now refactor and remove code duplication within the SWITCH statement. So I can do something like:
var projectRow = new DataConnection.ProjectRow();
switch (s)
{
case "category":
projectRow = projectTableAdapter.GetDataByCategory_Active_RankOrder(_category)[i];
break;
case "random":
projectRow = projectTableAdapter.GetDataByRandom()[i];
break;
}
if (image != null) image.ImageUrl = projectRow.Image;
if (title != null) title.Text = projectRow.Name;
if (summary != null) summary.Text = projectRow.Summary;
if (projectRow.Description.Length > 0)
{
if (link != null)
{
link.NavigateUrl = string.Format("/experience/details/?id={0}",
projectRow.ProjectID);
link.Visible = true;
}
}
if (listitem != null) listitem.Visible = true;
Since ProjectRow is an internal constructor of DataConnection that code is a no go. It should be doable I think...my brain just went on vacation after Cinco de Mayo it seems.
UPDATE:
Got it working using the following method. Forgot to just set the row initializer to 'null' and not using 'new'. Thanks for the information too, Henk.
DataConnection.ProjectRow projectRow = null;
switch (s)
{
case "category":
projectRow = projectTableAdapter.GetDataByCategory_Active_RankOrder(_category)[i];
break;
case "random":
projectRow = projectTableAdapter.GetDataByRandom()[i];
break;
}
if (image != null) if (projectRow != null) image.ImageUrl = projectRow.Image;
if (title != null) if (projectRow != null) title.Text = projectRow.Name;
if (summary != null) if (projectRow != null) summary.Text = projectRow.Summary;
if (projectRow != null && projectRow.Description.Length > 0)
{
if (link != null)
{
link.NavigateUrl = string.Format("/experience/details/?id={0}",
projectRow.ProjectID);
link.Visible = true;
}
}
if (listitem != null) listitem.Visible = true;
DataTable.Rows.Add() adds a row to the data table. However, how does it handle the underlying array?
When adding a single row at a time, does it rebuild the entire array with each row added?
Or is it able to simply modify the existing array without any hit on performance?
I am wondering if it’s better to determine the size of the array before filling it with data, or if somehow the data table is able to modify the collection without (behind the scenes) copying and moving things.
It’s my understanding that to adjust an array you have to redefine it and move previously existing data into the new structure.
My question is what is the work flow for the Collection.Add() method?
Take a look using software like DotPeek:
DataTable.Rows.Add(DataRow row)
{
this.table.AddRow(row, -1);
}
which calls:
DataTable.AddRow(DataRow row, int proposedID)
{
this.InsertRow(row, proposedID, -1);
}
which calls:
DataTable.InsertRow(DataRow row, int proposedID, int pos)
{
this.InsertRow(row, (long) proposedID, pos, true);
}
which calls:
DataTable.InsertRow(DataRow row, long proposedID, int pos, bool fireEvent)
{
Exception deferredException = (Exception) null;
if (row == null)
throw ExceptionBuilder.ArgumentNull("row");
if (row.Table != this)
throw ExceptionBuilder.RowAlreadyInOtherCollection();
if (row.rowID != -1L)
throw ExceptionBuilder.RowAlreadyInTheCollection();
row.BeginEdit();
int proposedRecord = row.tempRecord;
row.tempRecord = -1;
if (proposedID == -1L)
proposedID = this.nextRowID;
bool flag;
if (flag = this.nextRowID <= proposedID)
this.nextRowID = checked (proposedID + 1L);
try
{
try
{
row.rowID = proposedID;
this.SetNewRecordWorker(row, proposedRecord, DataRowAction.Add, false, false, pos, fireEvent, out deferredException);
}
catch
{
if (flag && this.nextRowID == proposedID + 1L)
this.nextRowID = proposedID;
row.rowID = -1L;
row.tempRecord = proposedRecord;
throw;
}
if (deferredException != null)
throw deferredException;
if (!this.EnforceConstraints || this.inLoad)
return;
int count = this.columnCollection.Count;
for (int index = 0; index < count; ++index)
{
DataColumn dataColumn = this.columnCollection[index];
if (dataColumn.Computed)
dataColumn.CheckColumnConstraint(row, DataRowAction.Add);
}
}
finally
{
row.ResetLastChangedColumn();
}
}
which calls:
DataTable.SetNewRecordWorker(DataRow row, int proposedRecord, DataRowAction action, bool isInMerge, bool suppressEnsurePropertyChanged, int position, bool fireEvent, out Exception deferredException)
{
deferredException = (Exception) null;
if (row.tempRecord != proposedRecord)
{
if (!this.inDataLoad)
{
row.CheckInTable();
this.CheckNotModifying(row);
}
if (proposedRecord == row.newRecord)
{
if (!isInMerge)
return;
this.RaiseRowChanged((DataRowChangeEventArgs) null, row, action);
return;
}
else
row.tempRecord = proposedRecord;
}
DataRowChangeEventArgs args = (DataRowChangeEventArgs) null;
try
{
row._action = action;
args = this.RaiseRowChanging((DataRowChangeEventArgs) null, row, action, fireEvent);
}
catch
{
row.tempRecord = -1;
throw;
}
finally
{
row._action = DataRowAction.Nothing;
}
row.tempRecord = -1;
int record = row.newRecord;
int num = proposedRecord != -1 ? proposedRecord : (row.RowState != DataRowState.Unchanged ? row.oldRecord : -1);
if (action == DataRowAction.Add)
{
if (position == -1)
this.Rows.ArrayAdd(row);
else
this.Rows.ArrayInsert(row, position);
}
List<DataRow> cachedRows = (List<DataRow>) null;
if ((action == DataRowAction.Delete || action == DataRowAction.Change) && (this.dependentColumns != null && this.dependentColumns.Count > 0))
{
cachedRows = new List<DataRow>();
for (int index = 0; index < this.ParentRelations.Count; ++index)
{
DataRelation relation = this.ParentRelations[index];
if (relation.ChildTable == row.Table)
cachedRows.InsertRange(cachedRows.Count, (IEnumerable<DataRow>) row.GetParentRows(relation));
}
for (int index = 0; index < this.ChildRelations.Count; ++index)
{
DataRelation relation = this.ChildRelations[index];
if (relation.ParentTable == row.Table)
cachedRows.InsertRange(cachedRows.Count, (IEnumerable<DataRow>) row.GetChildRows(relation));
}
}
if (!suppressEnsurePropertyChanged && !row.HasPropertyChanged && (row.newRecord != proposedRecord && -1 != proposedRecord) && -1 != row.newRecord)
{
row.LastChangedColumn = (DataColumn) null;
row.LastChangedColumn = (DataColumn) null;
}
if (this.LiveIndexes.Count != 0)
{
if (-1 == record && -1 != proposedRecord && (-1 != row.oldRecord && proposedRecord != row.oldRecord))
record = row.oldRecord;
DataViewRowState recordState1 = row.GetRecordState(record);
DataViewRowState recordState2 = row.GetRecordState(num);
row.newRecord = proposedRecord;
if (proposedRecord != -1)
this.recordManager[proposedRecord] = row;
DataViewRowState recordState3 = row.GetRecordState(record);
DataViewRowState recordState4 = row.GetRecordState(num);
this.RecordStateChanged(record, recordState1, recordState3, num, recordState2, recordState4);
}
else
{
row.newRecord = proposedRecord;
if (proposedRecord != -1)
this.recordManager[proposedRecord] = row;
}
row.ResetLastChangedColumn();
if (-1 != record && record != row.oldRecord && (record != row.tempRecord && record != row.newRecord) && row == this.recordManager[record])
this.FreeRecord(ref record);
if (row.RowState == DataRowState.Detached && row.rowID != -1L)
this.RemoveRow(row, false);
if (this.dependentColumns != null)
{
if (this.dependentColumns.Count > 0)
{
try
{
this.EvaluateExpressions(row, action, cachedRows);
}
catch (Exception ex)
{
if (action != DataRowAction.Add)
throw ex;
deferredException = ex;
}
}
}
try
{
if (!fireEvent)
return;
this.RaiseRowChanged(args, row, action);
}
catch (Exception ex)
{
if (!ADP.IsCatchableExceptionType(ex))
throw;
else
ExceptionBuilder.TraceExceptionWithoutRethrow(ex);
}
}
which calls one of those:
DataRowCollection.ArrayAdd(DataRow row)
{
row.RBTreeNodeId = this.list.Add(row);
}
DataRowCollection.ArrayInsert(DataRow row, int pos)
{
row.RBTreeNodeId = this.list.Insert(pos, row);
}
this.list is of type DataRowCollection.DataRowTree, derived from RBTree<DataRow>.
private sealed class DataRowTree : RBTree<DataRow>
RBTree<DataRow> and RBTreeNodeId allows us to conclude that a Red-Black tree is being used!
when i tab to itemFooter , databinding will getdata and load continue
public void getFeed()
{
waittingopen();
if (listRSS != null && listRSS.Count > 0)
{
List<Article> listArticle = getArticle();
if (listArticle.Count > 0)
{
if (loadmor != null && list.Items.Contains(loadmor))
{
list.Items.Remove(loadmor);
}
#region add item
for (int i = 0; i < listArticle.Count; i++)
{
dataDetail dataDetail;
if (i == 0 && dtListBoxx.Count == 0)
dataDetail = new dataDetail { title = listArticle[i].title, feedName = listRSS[indexLoadmor].name, Type = "itemBigContent", isVisileLineLeft = System.Windows.Visibility.Collapsed, isVisileBook = System.Windows.Visibility.Collapsed };
else
dataDetail = new dataDetail { title = listArticle[i].title, feedName = listRSS[indexLoadmor].name, Type = "itemContent", isVisileLineLeft = System.Windows.Visibility.Collapsed, isVisileBook = System.Windows.Visibility.Collapsed };
dtListBoxx.Add(dataDetail);
}
#endregion
if (intLoad == 0)
{
listArticle.Clear();
listArticle = null;
indexLoadmor++;
intLoad++;
getFeed();
}
else
{
intLoad = 0;
dataDetail dataLoadmoreItem = new dataDetail { Type = "itemFooter" };
dtListBoxx.Add(dataLoadmoreItem);
this.list.ItemsSource = dtListBoxx;
}
waittingClose();
}
else
{
getfeed = new Getfeed(listRSS[indexLoadmor].link.ToString(), "", listRSS[indexLoadmor].rid, intLoad);
getfeed.onComplete += new Getfeed.DownloadComplete(getfeed_onComplete);
if (intLoad == 1)
intLoad = 0;
}
}
}
how do i can load more data by using this.list.ItemsSource = dtListBoxx ? I tried but listbox is not updated when dataDetail add item
Please help me !
Use ObservableCollection instead of List. It automatically raises OnCollectionChanged event to notify view that some changes in collection are occurred.