[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 :wave:
Re: just a single line to explain
Quote:
Originally Posted by
MrtforCode
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 :wave:
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.
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?).
Re: just a single line to explain
Quote:
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
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.