Results 1 to 5 of 5

Thread: [RESOLVED] just a single line to explain

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2008
    Posts
    778

    Resolved [RESOLVED] just a single line to explain

    Code:
    cutidtext = datagridmainform.CurrentRow.Cells.Item("griacc").Value.ToString()
    cutidtext is a string

    can somebody please explain what would this end suppose to mean - ("griacc").Value.ToString()

    and what is the difference between this
    LeadsIdText = datagridleads.CurrentRow.Cells.Item(0).Value.ToString()

    got (0) in there, what would this mean ?

    thanks
    Last edited by MrtforCode; May 1st, 2009 at 07:32 AM.

  2. #2
    Addicted Member
    Join Date
    Apr 2009
    Location
    Near Dog River (sorta)
    Posts
    160

    Re: just a single line to explain

    Quote Originally Posted by MrtforCode View Post
    Code:
    cutidtext = datagridmainform.CurrentRow.Cells.Item("griacc").Value.ToString()
    cutidtext is a string

    can somebody please explain what would this end suppose to mean - ("griacc").Value.ToString()

    thanks
    It sounds to me that the field called "griacc" is an integer. To access this field, you need to use datagridmainform.CurrentRow.Cells.Item("griacc").Value

    To assign that value to a string (to perform string operations, for example), you need to convert the numerical representation to a string. The .ToString() method does that - it returns a string "version" of griacc.

    Just my guess though. Someone else will say for sure.
    PC #1: Athlon64 X2+Vista64+VS2008EE+.NET3.5 #2: XP (all flavours Ghost'd)+VS2008EE+.NET3.5
    Help Files: HelpMaker · Dr. Explain · Create Icons: IcoFX


    "Whoever eats my flesh and drinks my blood has eternal life, and I will raise him on the last day." John 6:54

  3. #3
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: just a single line to explain

    Cells, or columns, can be accessed by index or by column name. Your former example retrieves the cell by name, the latter by index.

    the .Cell.item(0) retrieves the first cell in the row (returning some kind of cell object); .Value gets the value object of that cell; .ToString converts the resultant value to a string.

    note that there is the chance that you can get a total of 5 errors on that single line (e.g. what if the .Value of the cell is Nothing?).
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  4. #4
    Hyperactive Member su ki's Avatar
    Join Date
    Oct 2007
    Posts
    354

    Re: just a single line to explain

    LeadsIdText = datagridleads.CurrentRow.Cells.Item(0).Value.ToString()

    got (0) in there, what would this mean ?
    datagridleads's current active row contains zero in its first column
    * If my post helped you, please Rate it
    * If your problem is solved please also mark the thread resolved it is there in right top of page under thread tools
    * Why Rating is useful

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: just a single line to explain

    Datagridview contains columns and rows.
    CurrentRow = the current selected row on the datagrid.
    CurrentRow.Cells = the collection of datagridviewcell in current row.
    CurrentRow.Cells.Item(x) = the datagridviewcell at column x in the current row. Note that x can be an integer denoted the column index or a string specified the name of the column.
    CurrentRow.Cells.Item(x).Value = the value of the of the cell which is in the current row at column x
    Since the value of a datagridview is type Object, thus the ToString call is to convert that object into a string.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

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