Click to See Complete Forum and Search --> : C# equivalent ?[Resolved]
Pirate
Apr 26th, 2003, 10:49 PM
Dim i As Integer
For i = 0 To flds.Length - 1
TreView.Nodes.Add(MyDataset.Tables(0).Columns.Item(i).ToString)
Next
Thanks
DevGrp
Apr 26th, 2003, 11:42 PM
for(int i = 0; i < flds.Lenght - 1; i++)
{
TreView.Nodes.Add(MyDataset.Tables[0].Columns[i].ToString());
}
Pirate
Apr 27th, 2003, 01:47 AM
Thanks DevGrp , I got another one if you can help ...
If TypeOf TxtBox Is TextBox Then
TxtBox.Text = ""
End If
Pirate
Apr 27th, 2003, 01:55 AM
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 !:rolleyes:
this works fine :
ListVItem = new ListViewItem();
ListVItem.Text = dr["C_URL"]+ "" ;
but not this :
ListVItem = new ListViewItem();
ListVItem.Text = dr["C_URL"] ;
Thanks .
DevGrp
Apr 27th, 2003, 02:33 AM
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.
If TypeOf TxtBox Is TextBox Then
TxtBox.Text = ""
End If
if(TxtBox is TextBox)
TxtBox.Text = "";
BrianHawley
Apr 27th, 2003, 02:34 AM
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 + "".
Pirate
Apr 27th, 2003, 07:51 AM
Thank you DevGrp .:)
CornedBee
Apr 28th, 2003, 03:07 AM
Or call ToString explicitly.
Pirate
Apr 28th, 2003, 03:10 AM
That's what I figured out actually !:D
session
May 6th, 2003, 07:29 PM
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.
if(TxtBox is TextBox)
TxtBox.Text = "";
I tried the 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?
CornedBee
May 7th, 2003, 01:08 AM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.