Results 1 to 11 of 11

Thread: C# equivalent ?[Resolved]

  1. #1

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    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.

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    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

  3. #3

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Thanks DevGrp , I got another one if you can help ...

    Code:
    If TypeOf TxtBox Is TextBox Then
    TxtBox.Text = ""
    End If

  4. #4

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 .

  5. #5
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    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:
    1. If TypeOf TxtBox Is TextBox Then
    2.     TxtBox.Text = ""
    3. End If
    Code:
    if(TxtBox is TextBox)
        TxtBox.Text = "";
    Dont gain the world and lose your soul

  6. #6
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796
    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)

  7. #7

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Thank you DevGrp .

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  9. #9

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    That's what I figured out actually !

  10. #10
    Member
    Join Date
    Apr 2003
    Location
    CANADA
    Posts
    63
    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?

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width