|
-
Apr 26th, 2003, 10:49 PM
#1
Thread Starter
Sleep mode
C# equivalent ?[Resolved]
Code:
Dim i As Integer
For i = 0 To flds.Length - 1
TreView.Nodes.Add(MyDataset.Tables(0).Columns.Item(i).ToString)
Next
Thanks
Last edited by Pirate; Apr 28th, 2003 at 03:14 AM.
-
Apr 26th, 2003, 11:42 PM
#2
Frenzied Member
Code:
for(int i = 0; i < flds.Lenght - 1; i++)
{
TreView.Nodes.Add(MyDataset.Tables[0].Columns[i].ToString());
}
Dont gain the world and lose your soul
-
Apr 27th, 2003, 01:47 AM
#3
Thread Starter
Sleep mode
Thanks DevGrp , I got another one if you can help ...
Code:
If TypeOf TxtBox Is TextBox Then
TxtBox.Text = ""
End If
-
Apr 27th, 2003, 01:55 AM
#4
Thread Starter
Sleep mode
Weird thing ! Why this works (when I add + "") but when I remove it , it won't work and says : Cannot implicitly convert type 'object' to 'string' .anyone can guess !
this works fine :
Code:
ListVItem = new ListViewItem();
ListVItem.Text = dr["C_URL"]+ "" ;
but not this :
Code:
ListVItem = new ListViewItem();
ListVItem.Text = dr["C_URL"] ;
Thanks .
-
Apr 27th, 2003, 02:33 AM
#5
Frenzied Member
The first one works because the ToString method of dr["C_URL"] is being called behind the scenes when the empty string is appended to the end. To make the one work, you have to explicity call the dr["C_URL"].ToString(). Remember every object implicitly inherits a ToString Method.
VB Code:
If TypeOf TxtBox Is TextBox Then
TxtBox.Text = ""
End If
Code:
if(TxtBox is TextBox)
TxtBox.Text = "";
Dont gain the world and lose your soul
-
Apr 27th, 2003, 02:34 AM
#6
Fanatic Member
The right hand side will be evaluated before putting the value into the left hand side.
The + "" forces the right hand side to convert.
Why it can't convert implicitly is a mystery. Either they missed it or somebody decided it should work that way.
You can always use the Convert statement if you want t avoid the + "".
Brian
(Fighting with the RightToLeft bugs in VS 2005)
-
Apr 27th, 2003, 07:51 AM
#7
Thread Starter
Sleep mode
Thank you DevGrp .
-
Apr 28th, 2003, 03:07 AM
#8
Or call ToString explicitly.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 28th, 2003, 03:10 AM
#9
Thread Starter
Sleep mode
That's what I figured out actually !
-
May 6th, 2003, 07:29 PM
#10
Member
Originally posted by DevGrp
The first one works because the ToString method of dr["C_URL"] is being called behind the scenes when the empty string is appended to the end. To make the one work, you have to explicity call the dr["C_URL"].ToString(). Remember every object implicitly inherits a ToString Method.
Code:
if(TxtBox is TextBox)
TxtBox.Text = "";
I tried the code
Code:
if(TxtBox is TextBox)
TxtBox.Text = "";
but it says 'the given expression is always of the provided (Ststem.Windows.Form.TextBox) type. What does that mean?
-
May 7th, 2003, 01:08 AM
#11
That means that TxtBox is of reference type TextBox and therefore can't reference any object where the if clause would be false. Therefore the if is useless.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
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
|