Invalid Data in Excel File. Index was outside the bounds of the array.C# - c#

Cant find answer in any of the suggestions.I am trying to upload an excel file to the postgre Db.
Here is the C# code :
public static List<Common.Transactions.TransactionDetail> GetTransactionDetails(string path)
{
if (!File.Exists(path))
{
return null;
}
var transactionDetails = new List<Common.Transactions.TransactionDetail>();
foreach (var sheet in Workbook.Worksheets(path))
{
int officeId = 0;
foreach (var row in sheet.Rows.Skip(1))
{
var td = new Common.Transactions.TransactionDetail
{
GlAccountId = Core.GlAccounts.GetGlAcccountId(row.Cells[1]?.Text),
AccountNumberId = Deposit.AccountHolders.GetAccountNumberId(row.Cells[2]?.Text),
ShareAccountId = Core.ShareAccounts.GetShareAccountId(row.Cells[3]?.Text),
LoanId = Loan.LoanAccounts.GetLoanId(row.Cells[4]?.Text),
Debit = row.Cells[5]?.Text.ToDecimal(),
Credit = row.Cells[6]?.Text.ToDecimal(),
StatementReference = row.Cells[7]?.Text
};
if (row.Cells[7] != null)
{
td.OfficeId = Office.Offices.GetOfficeIdByCode(row.Cells[7]?.Text);
officeId = Office.Offices.GetOfficeIdByCode(row.Cells[7]?.Text);
}
if (td.AccountNumberId == 0)
{
td.AccountNumberId = null;
}
if (td.LoanId == 0)
{
td.LoanId = null;
}
if (td.ShareAccountId == 0)
{
td.ShareAccountId = null;
}
if (row.Cells[0] != null)
{
td.AccountName = row.Cells[0].Text;
}
if (row.Cells[1] != null && string.IsNullOrWhiteSpace(td.AccountName))
{
td.AccountName = row.Cells[1].Text;
}
if (row.Cells[2] != null && string.IsNullOrWhiteSpace(td.AccountName))
{
td.AccountName = row.Cells[2].Text;
}
if (row.Cells[3] != null && string.IsNullOrWhiteSpace(td.AccountName))
{
td.AccountName = row.Cells[3].Text;
}
#region OfficeId
if (td.AccountNumberId != null)
{
officeId = Deposit.AccountHolders.GetAccountOfficeId(td.AccountNumberId.ToLong());
}
if (td.LoanId != null)
{
officeId = Loan.LoanGrant.GetAccountOfficeId(td.LoanId.ToLong());
}
if (td.ShareAccountId != null)
{
officeId = Core.ShareAccounts.GetAccountOfficeId(td.ShareAccountId.ToLong());
}
#endregion
td.OfficeId = officeId != 0 ? officeId : SessionHelper.GetOfficeId();
td.OfficeCode = Office.Offices.GetOfficeCode(officeId);
transactionDetails.Add(td);
}
}
foreach (var detail in transactionDetails)
{
if (detail.Debit.ToDecimal() > 0 && detail.Credit > 0)
{
throw new TransactionDetailException(
$#"Invalid transaction. Either debit or credit should be null for '{detail.AccountName}'.");
}
if (detail.AccountNumberId > 0)
{
if (detail.Debit.ToDecimal() > 0)
{
if (detail.Debit > Deposit.AccountHolders.GetDepositAccountBalance(detail.AccountNumberId.ToLong()))
{
throw new TransactionDetailException(
$#"Insufficient balance in account '{detail.AccountName}'.");
}
}
detail.GlAccountId = Deposit.AccountHolders.GetGlAccountId(detail.AccountNumberId);
}
if (detail.ShareAccountId > 0)
{
if (detail.Debit.ToDecimal() > 0)
{
if (detail.Debit > Core.ShareAccounts.GetShareBalance(detail.ShareAccountId.ToLong()))
{
throw new TransactionDetailException(
$#"Insufficient balance in account '{detail.AccountName}'.");
}
}
detail.GlAccountId = Core.ShareAccounts.GetGlAccountId(detail.ShareAccountId.ToLong());
}
if (detail.LoanId > 0)
{
if (detail.Credit.ToDecimal() > 0)
{
if (detail.Credit > Loan.LoanAccounts.GetLoanCollectionBalance(detail.LoanId.ToLong(), Core.DateConversion.GetCurrentServerDate()))
{
throw new TransactionDetailException(
$#"Insufficient balance in account '{detail.AccountName}'.");
}
}
detail.GlAccountId = Loan.LoanGrant.GetLoanTransactionGLAccountId(detail.LoanId.ToLong());
}
detail.AuditUserId = Common.Helpers.SessionHelper.GetUserId();
detail.AccountNumberId = detail.AccountNumberId <= 0 ? null : detail.AccountNumberId;
detail.LoanId = detail.LoanId <= 0 ? null : detail.LoanId;
detail.ShareAccountId = detail.ShareAccountId <= 0 ? null : detail.ShareAccountId;
detail.EnableDeleteButton = true;
if (detail.GlAccountId == 0)
{
throw new TransactionDetailException($#"{detail.AccountName} is not a valid account.");
}
}
return transactionDetails;
}
}
I get error Index was outside the bounds of array.Invalid excel data.
My excel data
Gl Account Deposit A/C Share A/C Loan A/C Debit Credit Statement Reference
Loss Recovery Fund 0 1000 uploaded from excel
Risk Coverage Fund 0 1106 uploaded from excel

Ok solved it..The problem was with my excel data.
I was looking for row[7] which didnt exist.Had to add one column to the
excel file and it worked.
The exception was here in the code :
if (row.Cells[7] != null)
{
td.OfficeId = Office.Offices.GetOfficeIdByCode(row.Cells[7]?.Text);
officeId = Office.Offices.GetOfficeIdByCode(row.Cells[7]?.Text);
}
Thanks #LocEngineer Sir for your time.

Related

C# - System.FormatException SQLite connection

I am experiencing an error that I cannot understand, can anyone explain to me what I am miserably doing wrong?
Database Table:
CREATE TABLE "posti_auto_mil" (
"n_posto" TEXT NOT NULL UNIQUE,
"id_utente" INTEGER NOT NULL,
"targa_1" TEXT NOT NULL,
"targa_2" TEXT NOT NULL,
"targa_3" TEXT NOT NULL,
"targa_4" TEXT NOT NULL,
"targa_5" TEXT NOT NULL,
"locazione" TEXT NOT NULL
);
LoadCar.cs
public static bool CheckTarga(int idUtente)
{
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
{
var output = cnn.Query($"select * from utenti where id = {idUtente}").FirstOrDefault();
if (output != null)
{
var targa = cnn.Query($"select * from posti_auto_mil where id = {idUtente}").FirstOrDefault();
if (targa != null)
{
var checkpresenza = cnn.Query($"select locazione from posti_auto_mil where id_utente = {idUtente} limit 1");
if (checkpresenza.ToString() == "interno")
{
targaicon = 1;
}
else if (checkpresenza.ToString() == "esterno")
{
targaicon = 2;
}
else if (checkpresenza.ToString() == "provvisorio")
{
targaicon = 2;
}
else targaicon = 3;
}
return true;
}
else
{
targaicon = 3;
return false;
}
}
Form1.cs
//Parking
//Visibilità
listView_targheinfo.Items.Clear();
listView_targheinfo.Visible = true;
pictureBox_infobox.Visible = true;
if (Classi.LoadCar.CheckTarga(Int32.Parse(home_textBox_id.Text)) == true)
{
if (Classi.LoadCar.targaicon == 1)
{
pictureBox_infobox.BackgroundImage = global::RegistroAccessi_8Rgt.Properties.Resources.parking_32px_green;
}
else if (Classi.LoadCar.targaicon == 2)
{
pictureBox_infobox.BackgroundImage = global::RegistroAccessi_8Rgt.Properties.Resources.no_parking_32px;
}
else if (Classi.LoadCar.targaicon == 3)
{
pictureBox_infobox.BackgroundImage = global::RegistroAccessi_8Rgt.Properties.Resources.parking_32px_yellow;
}
else
{
pictureBox_infobox.BackgroundImage = global::RegistroAccessi_8Rgt.Properties.Resources.no_parking_32px;
}
}
else
{
pictureBox_infobox.BackgroundImage = global::RegistroAccessi_8Rgt.Properties.Resources.no_parking_32px;
}
Error:
I've done various tests but I don't understand what I'm doing wrong... can someone clarify this for me?
I can do a personnel search in the same way but I can't do it for vehicle number plates.

How to convert Footnote to endnotes with title using vsto?

How to add title to the endnotes using vsto? Any suggestions would be appreciable.
I have tried the following code:
public void ConvertFootNoteToEndNote(Word.Document myDocx, ref string sErrMsg)
{
try
{
Word.WdNoteNumberStyle FootNoteNumberStyle;
if (!(myDocx.Endnotes.Count > 0 && myDocx.Footnotes.Count > 0))
{
if (myDocx.Footnotes.Count > 0)
{
FootNoteNumberStyle = myDocx.Footnotes.NumberStyle;
myDocx.Footnotes.Convert();
myDocx.Endnotes.NumberStyle = FootNoteNumberStyle;
}
}
Word.Range rnFootNoteRange = null;
if (myDocx.Endnotes.Count > 0)
{
rnFootNoteRange = myDocx.StoryRanges[Word.WdStoryType.wdEndnotesStory];
if (rnFootNoteRange.Paragraphs.Count != 0)
if (rnFootNoteRange.Paragraphs[1].Range.Text != null)
if (rnFootNoteRange.Paragraphs[1].Range.Text.Length < 15)
if (rnFootNoteRange.Paragraphs[1].Range.Text.ToUpper().Contains("NOTE"))
return;
rnFootNoteRange.Paragraphs.Add(rnFootNoteRange);
Word.Paragraph objNewParagraph = rnFootNoteRange.Paragraphs.Add(rnFootNoteRange);
}
}
catch (Exception ex)
{
sErrMsg = ex.StackTrace;
throw;
}
}
It is working fine but I want to add title for the endnote.
I found.
public void ConvertFootNoteToEndNote(Word.Document myDocx, ref string sErrMsg)
{
try
{
Word.WdNoteNumberStyle FootNoteNumberStyle;
if (!(myDocx.Endnotes.Count > 0 && myDocx.Footnotes.Count > 0))
{
if (myDocx.Footnotes.Count > 0)
{
FootNoteNumberStyle = myDocx.Footnotes.NumberStyle;
myDocx.Footnotes.Convert();
myDocx.Endnotes.NumberStyle = FootNoteNumberStyle;
}
}
Word.Range rnFootNoteRange = null;
if (myDocx.Endnotes.Count > 0)
{
rnFootNoteRange = myDocx.StoryRanges[Word.WdStoryType.wdEndnotesStory];
if (rnFootNoteRange.Paragraphs.Count != 0)
if (rnFootNoteRange.Paragraphs[1].Range.Text != null)
if (rnFootNoteRange.Paragraphs[1].Range.Text.Length < 15)
if (rnFootNoteRange.Paragraphs[1].Range.Text.ToUpper().Contains("NOTE"))
return;
rnFootNoteRange.Paragraphs.Add(rnFootNoteRange);
Word.Paragraph objNewParagraph = rnFootNoteRange.Paragraphs.Add(rnFootNoteRange);
//if (objNewParagraph != null)
// objNewParagraph.Range.Text = myDocx.Endnotes.Count > 1 ? "Notes" : "Note";
}
}
catch (Exception ex)
{
sErrMsg = ex.StackTrace;
throw;
}
}

Nullable Property throwing NullReferenceException on .HasValue

This line of (C#) code
if (!currentLap.S1.HasValue)
is giving me
System.NullReferenceException: Object reference not set to an instance of an object.
provided I'm sure that currentLap variable is instantiated (because it's being used a few lines before and it is a local variable) and it has following property:
private double? _s1;
[DefaultValue(null)]
[JsonConverter(typeof(ShortDoubleConverter))]
public double? S1
{
get { return _s1; }
set { _s1 = value; }
}
how can it possibly throw NullReferenceException? Can it be something to do with optimization on Release mode?
Thanks,
Stevo
EDIT:
here is full method code.
public void Update(DriverData driverData)
{
LapInfo currentLap = this.CurrentLap;
if (currentLap != null &&
this.LastDriverData != null &&
driverData.TotalLaps != this.LastDriverData.TotalLaps &&
driverData.InPits &&
driverData.Speed < 10 &&
!this.LastDriverData.InPits)
{
currentLap.Escaped = true;
}
this.LastDriverData = driverData;
if ((currentLap == null || currentLap.Lap != driverData.LapNumber) &&
!this.Laps.TryGetValue(driverData.LapNumber, out currentLap))
{
currentLap = new LapInfo() { Lap = driverData.LapNumber, Parent = this, Class = driverData.Class };
this.Laps.Add(driverData.LapNumber, currentLap);
int lapsCount = 0, completedDriverLaps = 0, cleanLaps = 0;
this.TotalLaps = driverData.TotalLaps;
//if it's not the first lap
if (driverData.TotalLaps > 0)
{
//previous lap
if (this.CurrentLap == null || !this.CurrentLap.Escaped)
{
this.CompletedLaps++;
if (this.CurrentLap == null || !this.CurrentLap.MaxIncident.HasValue)
this.CleanLaps++;
}
}
foreach (DriverLapsInfo laps in this.Parent.LapsByVehicle.Values)
{
lapsCount += laps.TotalLaps;
completedDriverLaps += laps.CompletedLaps;
cleanLaps += laps.CleanLaps;
}
this.Parent.Parent.SetLapsCount(driverData, lapsCount, driverData.Class, completedDriverLaps, cleanLaps);
}
this.CurrentLap = currentLap;
//add incidents
if (driverData.Incidents != null)
{
foreach (IncidentScore incident in driverData.Incidents)
{
this.CurrentLap.MaxIncident = Math.Max(this.CurrentLap.MaxIncident ?? 0, incident.Strength);
this.CurrentLap.Incidents++;
this.Incidents++;
}
}
LapInfo previousLap = null;
if ((this.PreviousLap == null || this.PreviousLap.Lap != driverData.TotalLaps) &&
this.Laps.TryGetValue(driverData.TotalLaps, out previousLap))
{
this.PreviousLap = previousLap;
if (!this.PreviousLap.Date.HasValue)
{
this.PreviousLap.Date = DateTime.UtcNow;
}
}
if (currentLap.Position == 0)
currentLap.Position = driverData.Position;
if (driverData.CurrentS1 > 0)
{
**if (!currentLap.S1.HasValue)**
{
this.UpdateBestS1(driverData.BestS1);
this.Parent.Parent.UpdateBestS1(driverData.BestS1, driverData.UniqueName);
currentLap.UpdateS1(driverData.CurrentS1, driverData);
//reset the best split set at the finish line
if (this.PreviousLap != null && this.PreviousLap.SplitBest < 0)
this.PreviousLap.SplitBest = 0;
}
if (driverData.CurrentS2.HasValue && driverData.CurrentS1.HasValue && !currentLap.S2.HasValue)
{
double s2 = driverData.CurrentS2.Value - driverData.CurrentS1.Value;
this.UpdateBestS2(s2);
this.Parent.Parent.UpdateBestS2(s2, driverData.UniqueName);
currentLap.UpdateS2(s2, driverData);
}
}
if (this.PreviousLap != null)
{
if (driverData.LastLap > 0)
{
if (!this.PreviousLap.S3.HasValue && driverData.LastS2.HasValue)
{
double s3 = driverData.LastLap.Value - driverData.LastS2.Value;
this.UpdateBestS3(s3);
this.Parent.Parent.UpdateBestS3(s3, driverData.UniqueName);
this.PreviousLap.UpdateS3(s3, driverData);
}
if (!this.PreviousLap.LapTime.HasValue)
{
double? bestLap = this.Parent.Parent.BestLap;
this.PreviousLap.UpdateLapTime(driverData, 0);
this.Parent.Parent.UpdateBestLap(this.PreviousLap, driverData.BestLap, driverData);
this.UpdateBestLap(driverData.BestLap, this.PreviousLap);
this.PreviousLap.UpdateLapTime(driverData, bestLap);
}
}
else
{
if (this.PreviousLap.SplitBest.HasValue)
this.PreviousLap.UpdateBestSplit();
if (this.PreviousLap.SplitSelf.HasValue)
this.PreviousLap.UpdateSelfSplit();
}
}
if (driverData.InPits)
{
switch (driverData.Sector)
{
case Sectors.Sector1:
if (previousLap != null)
previousLap.InPits = true;
break;
case Sectors.Sector3:
currentLap.InPits = true;
break;
}
}
//lap to speed
if (currentLap.TopSpeed < driverData.Speed)
{
driverData.TopSpeedLap = driverData.Speed;
currentLap.UpdateTopSpeed(driverData.Speed);
}
else
driverData.TopSpeedLap = currentLap.TopSpeed;
//overall top speed
if (this.TopSpeed < driverData.Speed)
{
driverData.TopSpeed = driverData.Speed;
this.TopSpeed = driverData.Speed;
this.Parent.Parent.UpdateTopSpeed(this.TopSpeed, driverData);
}
else
driverData.TopSpeed = this.TopSpeed;
}
There is no way on earth the code can make it to that line and currentLap beeing null.
Or am I going crazy? :)
.HasValue will not throw if the nullable reference is null, but a.b.HasValue will if a is null.
I suspect that currentLap == null. I know you say you're sure that currentLap is not null, but I think that's the most likely explanation. Can you post more code?
Update:
Thanks for posting your code.
This doesn't throw:
void Main() {
var f = new Foo();
Console.WriteLine (f.S1);
Console.WriteLine (f.S1.HasValue);
}
class Foo {
private double? _s1 = null;
public double? S1 {
get { return _s1; }
set { _s1 = value; }
}
}
Could you try to create a minimal reproduction? (minimal code that exhibits the issue)
Maybe have a look at the previous line of code :) - debugger often highlights the next line after the one where the NullReferenceException was actually thrown.

Workflow for Collection.Add()

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!

how to load more data binding?

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.

Categories

Resources