473,395 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

getting value from cell

Hi,
Easy question. It seems to me that I'm following the examples correctly,
but apparently I'm not. I'm trying to retrieve the data from a row called
"row" and a column called "File". This is what I have: (xFile is the int
value in column File and tCat is the table)

First I try:
xFile = int.Parse((tCat.Rows[row]["File"]).ToString());

Another example I found:
DataRow dRow = tCat.Rows[row];
xFile = int.Parse(dRow["File"].ToString());

Instead of getting the value back, I'm consistently getting the row, or index.
Thanks!!!
Mel
Nov 17 '05 #1
6 2229
Hi Mel,

Both those examples look fine to me.

Are you sure that the "File" column contains int values?

You may also omit the ".ToStirng()" bit.

Best,
Andre

Nov 17 '05 #2
Mel,

What is the value that should be in the file column? If it is not an
integer, I imagine that you would get exceptions in these cases. The "row"
variable is an index of a row in the table.

Also, the value in the column does not need to be parsed. Rather, you
can just cast to the type you need (assuming that there is a cast
available), like so:

xFile = (int) tCat.Rows[row]["File"];

However, something tells me that you don't want to cast to an integer,
but rather, to a string.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"melanieab" <me*******@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
Hi,
Easy question. It seems to me that I'm following the examples correctly,
but apparently I'm not. I'm trying to retrieve the data from a row called
"row" and a column called "File". This is what I have: (xFile is the int
value in column File and tCat is the table)

First I try:
xFile = int.Parse((tCat.Rows[row]["File"]).ToString());

Another example I found:
DataRow dRow = tCat.Rows[row];
xFile = int.Parse(dRow["File"].ToString());

Instead of getting the value back, I'm consistently getting the row, or
index.
Thanks!!!
Mel

Nov 17 '05 #3
The value in the File column is an integer, which is loaded from an xml file
(it's the attribute (ID) of whichever file). I load the table using a loop
containing:

tCat.Rows.Add(new object[]{nodeF.Item(i).Attributes["ID"].Value, ...});

where nodeF is the xmlNodeList = xml.GetElementsByTagName("File");

Actually, the code worked fine back when I would just load straight from the
xml file and retrieve the File value. But now, a column header is clicked so
the files are sorted alphabetically. When I click, I have no problem getting
the new row number, but I can't get the File value of that row. I can see
the numbers in the File column, and they're correct, I just can't retrieve
them.

Any suggestions?
Mel

"Nicholas Paldino [.NET/C# MVP]" wrote:
Mel,

What is the value that should be in the file column? If it is not an
integer, I imagine that you would get exceptions in these cases. The "row"
variable is an index of a row in the table.

Also, the value in the column does not need to be parsed. Rather, you
can just cast to the type you need (assuming that there is a cast
available), like so:

xFile = (int) tCat.Rows[row]["File"];

However, something tells me that you don't want to cast to an integer,
but rather, to a string.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"melanieab" <me*******@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
Hi,
Easy question. It seems to me that I'm following the examples correctly,
but apparently I'm not. I'm trying to retrieve the data from a row called
"row" and a column called "File". This is what I have: (xFile is the int
value in column File and tCat is the table)

First I try:
xFile = int.Parse((tCat.Rows[row]["File"]).ToString());

Another example I found:
DataRow dRow = tCat.Rows[row];
xFile = int.Parse(dRow["File"].ToString());

Instead of getting the value back, I'm consistently getting the row, or
index.
Thanks!!!
Mel


Nov 17 '05 #4
Mel,

I assume this is attached to a grid of some kind. Because of this, the
grid is bound to the DataView returned by the DefaultView property on the
DataTable. This returns the view that the grid is bound to. When you
change the sort order, it is on this view, not the data table itself (those
are never ordered, or at least, there should not be expectation of ordering
unless you know how it was populated).

What you want to do is use the view returned from the DefaultView
property, like so (you might have to tweak this):

// Get the view.
DataView view = tCat.DefaultView;

// Get the id.
xFile = (int) view.Rows[row]["File"];

That should work.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"melanieab" <me*******@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
The value in the File column is an integer, which is loaded from an xml
file
(it's the attribute (ID) of whichever file). I load the table using a
loop
containing:

tCat.Rows.Add(new object[]{nodeF.Item(i).Attributes["ID"].Value, ...});

where nodeF is the xmlNodeList = xml.GetElementsByTagName("File");

Actually, the code worked fine back when I would just load straight from
the
xml file and retrieve the File value. But now, a column header is clicked
so
the files are sorted alphabetically. When I click, I have no problem
getting
the new row number, but I can't get the File value of that row. I can see
the numbers in the File column, and they're correct, I just can't retrieve
them.

Any suggestions?
Mel

"Nicholas Paldino [.NET/C# MVP]" wrote:
Mel,

What is the value that should be in the file column? If it is not an
integer, I imagine that you would get exceptions in these cases. The
"row"
variable is an index of a row in the table.

Also, the value in the column does not need to be parsed. Rather,
you
can just cast to the type you need (assuming that there is a cast
available), like so:

xFile = (int) tCat.Rows[row]["File"];

However, something tells me that you don't want to cast to an
integer,
but rather, to a string.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"melanieab" <me*******@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
> Hi,
> Easy question. It seems to me that I'm following the examples
> correctly,
> but apparently I'm not. I'm trying to retrieve the data from a row
> called
> "row" and a column called "File". This is what I have: (xFile is the
> int
> value in column File and tCat is the table)
>
> First I try:
> xFile = int.Parse((tCat.Rows[row]["File"]).ToString());
>
> Another example I found:
> DataRow dRow = tCat.Rows[row];
> xFile = int.Parse(dRow["File"].ToString());
>
> Instead of getting the value back, I'm consistently getting the row, or
> index.
> Thanks!!!
> Mel
>
>


Nov 17 '05 #5
Thanks so much!!!
Mel

"Nicholas Paldino [.NET/C# MVP]" wrote:
Mel,

I assume this is attached to a grid of some kind. Because of this, the
grid is bound to the DataView returned by the DefaultView property on the
DataTable. This returns the view that the grid is bound to. When you
change the sort order, it is on this view, not the data table itself (those
are never ordered, or at least, there should not be expectation of ordering
unless you know how it was populated).

What you want to do is use the view returned from the DefaultView
property, like so (you might have to tweak this):

// Get the view.
DataView view = tCat.DefaultView;

// Get the id.
xFile = (int) view.Rows[row]["File"];

That should work.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"melanieab" <me*******@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
The value in the File column is an integer, which is loaded from an xml
file
(it's the attribute (ID) of whichever file). I load the table using a
loop
containing:

tCat.Rows.Add(new object[]{nodeF.Item(i).Attributes["ID"].Value, ...});

where nodeF is the xmlNodeList = xml.GetElementsByTagName("File");

Actually, the code worked fine back when I would just load straight from
the
xml file and retrieve the File value. But now, a column header is clicked
so
the files are sorted alphabetically. When I click, I have no problem
getting
the new row number, but I can't get the File value of that row. I can see
the numbers in the File column, and they're correct, I just can't retrieve
them.

Any suggestions?
Mel

"Nicholas Paldino [.NET/C# MVP]" wrote:
Mel,

What is the value that should be in the file column? If it is not an
integer, I imagine that you would get exceptions in these cases. The
"row"
variable is an index of a row in the table.

Also, the value in the column does not need to be parsed. Rather,
you
can just cast to the type you need (assuming that there is a cast
available), like so:

xFile = (int) tCat.Rows[row]["File"];

However, something tells me that you don't want to cast to an
integer,
but rather, to a string.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"melanieab" <me*******@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
> Hi,
> Easy question. It seems to me that I'm following the examples
> correctly,
> but apparently I'm not. I'm trying to retrieve the data from a row
> called
> "row" and a column called "File". This is what I have: (xFile is the
> int
> value in column File and tCat is the table)
>
> First I try:
> xFile = int.Parse((tCat.Rows[row]["File"]).ToString());
>
> Another example I found:
> DataRow dRow = tCat.Rows[row];
> xFile = int.Parse(dRow["File"].ToString());
>
> Instead of getting the value back, I'm consistently getting the row, or
> index.
> Thanks!!!
> Mel
>
>


Nov 17 '05 #6
Although in case anyone ever needs this, the exact syntax that works is
xFile = int.Parse(dv[row].Row["File"].ToString());

"melanieab" wrote:
Thanks so much!!!
Mel

"Nicholas Paldino [.NET/C# MVP]" wrote:
Mel,

I assume this is attached to a grid of some kind. Because of this, the
grid is bound to the DataView returned by the DefaultView property on the
DataTable. This returns the view that the grid is bound to. When you
change the sort order, it is on this view, not the data table itself (those
are never ordered, or at least, there should not be expectation of ordering
unless you know how it was populated).

What you want to do is use the view returned from the DefaultView
property, like so (you might have to tweak this):

// Get the view.
DataView view = tCat.DefaultView;

// Get the id.
xFile = (int) view.Rows[row]["File"];

That should work.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"melanieab" <me*******@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
The value in the File column is an integer, which is loaded from an xml
file
(it's the attribute (ID) of whichever file). I load the table using a
loop
containing:

tCat.Rows.Add(new object[]{nodeF.Item(i).Attributes["ID"].Value, ...});

where nodeF is the xmlNodeList = xml.GetElementsByTagName("File");

Actually, the code worked fine back when I would just load straight from
the
xml file and retrieve the File value. But now, a column header is clicked
so
the files are sorted alphabetically. When I click, I have no problem
getting
the new row number, but I can't get the File value of that row. I can see
the numbers in the File column, and they're correct, I just can't retrieve
them.

Any suggestions?
Mel

"Nicholas Paldino [.NET/C# MVP]" wrote:

> Mel,
>
> What is the value that should be in the file column? If it is not an
> integer, I imagine that you would get exceptions in these cases. The
> "row"
> variable is an index of a row in the table.
>
> Also, the value in the column does not need to be parsed. Rather,
> you
> can just cast to the type you need (assuming that there is a cast
> available), like so:
>
> xFile = (int) tCat.Rows[row]["File"];
>
> However, something tells me that you don't want to cast to an
> integer,
> but rather, to a string.
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - mv*@spam.guard.caspershouse.com
>
> "melanieab" <me*******@discussions.microsoft.com> wrote in message
> news:F2**********************************@microsof t.com...
> > Hi,
> > Easy question. It seems to me that I'm following the examples
> > correctly,
> > but apparently I'm not. I'm trying to retrieve the data from a row
> > called
> > "row" and a column called "File". This is what I have: (xFile is the
> > int
> > value in column File and tCat is the table)
> >
> > First I try:
> > xFile = int.Parse((tCat.Rows[row]["File"]).ToString());
> >
> > Another example I found:
> > DataRow dRow = tCat.Rows[row];
> > xFile = int.Parse(dRow["File"].ToString());
> >
> > Instead of getting the value back, I'm consistently getting the row, or
> > index.
> > Thanks!!!
> > Mel
> >
> >
>
>
>


Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brian Alexander | last post by:
Hello; I am trying to determine all of the cell attributes active on a given cell of a curses window. I start by getting a value that contains the attribute and character at the specified...
2
by: Graham Y | last post by:
I have a datagrid, populated via a SQL dataset, and I want the user to select a row by clicking on it and then using the value in the first cell as my key for my next query. Using...
2
by: TadPole | last post by:
Hi all, My main problems are::::::::: 1. Set a value within a block container that can be used and changed by subsequent templates/block-containers/tables etc.. 2. get/determine/find the...
4
by: Neil | last post by:
I have a gridview which is being populated with no problems. I want to be able to reference the data from the cells in the row but having followed an example on MSDN cannot get any data to be...
2
by: niceguy | last post by:
Hi I was wondering if its possible to get the exact displayed text from a cell in a datagrid. I need to get the displayed text and not any 'real' database value or anything that the cell...
2
by: news.microsoft.com | last post by:
Hi guys, I have a problem with the DataGridView. I want to catch the value of a cell when the user is editing it. Actually, I can't figure if there is an event or a property to get this value. ...
8
by: ipy2006 | last post by:
In my HTML I have, <input type="button" class="cartonsumkey" value="Sum Cartons" onclick="sumup(this);" /> In an external file that is called in Head area, I have, function sumup( o ) { ...
1
by: qiong | last post by:
Dear friends, Good evening, I have some problems with finding keyword ":\" for each cell. My objective is to find that keyword in each cell in each worksheet which represent the link. Eg:...
2
by: mylog | last post by:
Hi I am having a problem of getting the value from the dynamically generated table and dropdownlist. What I am facing is, I have created a table in the aspx page and now I need to add values to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.