|
-
Jul 24th, 2007, 02:29 PM
#1
Thread Starter
Fanatic Member
what am i doing wrong(bindingsource loop)
Hi all
Im trying to loop through spesific coloums of a bindingsource but i am having some trouble
the code i have so far is
c# Code:
private void CountLines(BindingSource bs)
{
int x = 0;
foreach (DataRowView IncidentRow in bs)
{
MessageBox.Show(IncidentRow.ToString());
x++;
}//foreach (DataRowView invoiceRow in invoicebindingsource)
MessageBox.Show(x.ToString());
}
But all i get out is

so my question is how would i say messagebox.show each summary or each ref num?
thanks
Crash
-
Jul 24th, 2007, 03:52 PM
#2
Re: what am i doing wrong(bindingsource loop)
Hi there,
You need to specify which column in the row you want to view buy its index or name:
Code:
MessageBox.Show(IncidentRow.Row["ref_num"].ToString());
-
Jul 24th, 2007, 04:34 PM
#3
Thread Starter
Fanatic Member
Re: what am i doing wrong(bindingsource loop)
bingo
thanks
if i were to want to save it back how would that go?
-
Jul 25th, 2007, 01:38 AM
#4
Re: what am i doing wrong(bindingsource loop)
Save what back, and back to what?
-
Jul 25th, 2007, 12:37 PM
#5
Thread Starter
Fanatic Member
Re: what am i doing wrong(bindingsource loop)
Sorry i was not very spesific
after i can access the data by row and col if i wanted to make a change to that cell how would i?
I mocked up some sudo code that might give you an idea of what im trying to figure out.
c# Code:
private void CountLines(BindingSource bs)
{
int x = 0;
foreach (DataRowView IncidentRow in bs)
{
If(IncidentRow.Row["ref_num"].ToString(); == stringimadeup)
{
replace incidentrow.row["ref_num"].tostring with "N/A"
}
x++;
}//foreach (DataRowView invoiceRow in invoicebindingsource)
MessageBox.Show(x.ToString());
}
-
Jul 25th, 2007, 07:46 PM
#6
Re: what am i doing wrong(bindingsource loop)
DataRowViews are almost the same as a DataRow. They are a view to the data in that row and can be used in almost exactly the same way:
Code:
foreach (DataRowView view in myBindingSource)
{
if ((string)view["ref_num"] = "some string")
{
view["ref_num"] = "N/A";
}
}
Note that if the column already contains string objects then you should cast as type string rather than call the ToString method. Why convert a string to a string? If you're unsure of the type then you should cal ToString to ensure it works in all cases.
-
Jul 25th, 2007, 09:15 PM
#7
Thread Starter
Fanatic Member
Re: what am i doing wrong(bindingsource loop)
 Originally Posted by jmcilhinney
DataRowViews are almost the same as a DataRow. They are a view to the data in that row and can be used in almost exactly the same way:
Code:
foreach (DataRowView view in myBindingSource)
{
if ((string)view["ref_num"] = "some string")
{
view["ref_num"] = "N/A";
}
}
Note that if the column already contains string objects then you should cast as type string rather than call the ToString method. Why convert a string to a string? If you're unsure of the type then you should cal ToString to ensure it works in all cases.
thanks so much ill give it a shot when i get into work tommrow
i would give you a +rate but i cant give you anymore
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|