How to select current column specific value from BindingSource
-
Tuesday, May 04, 2010 4:41 PM
Hi
I was wondering if anyone can help me.
I have a BindingSource in my Windows Form and this is linked to a table which has two columns one is 'id' and the other is 'PO' there is only one row which shows in there as i have filtered it that way. So what i am trying to do is retrieve the current value under the 'PO' column.
I have written this code in vb before and it works perfectly. I need to know what the C# code is.
The VB code was : label1.text = me.BindingSource1.current("PO").ToString()
I have tried the following codes for C#
label1.text = this.BindingSource1.current("PO").ToString();
also
label1.text = this.BindingSource1.current("PO".ToString().ToString());
it keeps throwing up the following error : Non-Invocable member 'systems.windows.forms.bindingsource.current' cannot be used like a method.
Please can someone help.
Regards
K
All Replies
-
Tuesday, May 04, 2010 5:56 PM
Welcome to the MSDN Forums.
In C# [] (brackets) are indexers instead of () (parentheses in VB). so, please try following instead:
label1.text = this.BindingSource1.Current["PO"].ToString();//also 'Current' insteaf of 'current'
Regards,
Yasser.
Don't be stickler and wine with William Shakespeare after the solution :^)
"And this our life, exempt from public haunt, finds tongues in trees, books in the running brooks, sermons in stones, and good in everything." William Shakespeare -
Tuesday, May 04, 2010 6:25 PM
Hi Yasser
Thankyou for your reply. I have just tried your suggestion and it still doesnt work
error message is 'cannot apply indexing with [ ] to an expression of type object
anymore suggestions?
would be appreciated
Thanks
-
Tuesday, May 04, 2010 7:00 PM
Yes,
label1.text = ((DataRowView)this.BindingSource1.Current).Row["PO"].ToString();
Don't be stickler and wine with William Shakespeare after the solution :^)
"And this our life, exempt from public haunt, finds tongues in trees, books in the running brooks, sermons in stones, and good in everything." William Shakespeare- Marked As Answer by Harry ZhuModerator Wednesday, May 12, 2010 8:49 AM
-
Wednesday, May 05, 2010 12:58 AM
// Convert the current object into the original class (typesafe)
MyObject value = this.bindingsource1.Current as MyObject;
if( value != null )
label1.text = value.PO;
Ken- Marked As Answer by Harry ZhuModerator Wednesday, May 12, 2010 8:49 AM
-
Friday, January 21, 2011 9:05 PMThank you very much, great solution.
-
Saturday, September 15, 2012 7:59 PM
I neep help pls.
I'm using Visual Studio C# 2010.
I have the same problem mentioned by the topic. I want to select current column specific value from BindingSource.
I tried this we you said,
label1.Text = ((DRW)this.kanalParametreBindingSource.Current).Row["ProjeAdi"].ToString();
I got an error like that ;
Error 1 'KMT.Form1.DRW' is a 'field' but is used like a 'type'
If i tried,
label1.Text = ((this.DRW).(this.kanalParametreBindingSource.Current)).Row["ProjeAdi"].ToString();
I got this error ;
Error 1 Identifier expected
(after ((this.DRW).( )
I also tried to select current specific value directly from BindingSource which is more important for my program. I can get the position number between records, but cannot reach a specific column in the current position.
Can you help me?
Best regards,
- Edited by Tavananna Saturday, September 15, 2012 8:06 PM

