473,785 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2247
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.co m

"melanieab" <me*******@disc ussions.microso ft.com> wrote in message
news:F2******** *************** ***********@mic rosoft.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(n ew object[]{nodeF.Item(i). Attributes["ID"].Value, ...});

where nodeF is the xmlNodeList = xml.GetElements ByTagName("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.co m

"melanieab" <me*******@disc ussions.microso ft.com> wrote in message
news:F2******** *************** ***********@mic rosoft.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.DefaultVie w;

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

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

"melanieab" <me*******@disc ussions.microso ft.com> wrote in message
news:CE******** *************** ***********@mic rosoft.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(n ew object[]{nodeF.Item(i). Attributes["ID"].Value, ...});

where nodeF is the xmlNodeList = xml.GetElements ByTagName("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.co m

"melanieab" <me*******@disc ussions.microso ft.com> wrote in message
news:F2******** *************** ***********@mic rosoft.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.DefaultVie w;

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

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

"melanieab" <me*******@disc ussions.microso ft.com> wrote in message
news:CE******** *************** ***********@mic rosoft.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(n ew object[]{nodeF.Item(i). Attributes["ID"].Value, ...});

where nodeF is the xmlNodeList = xml.GetElements ByTagName("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.co m

"melanieab" <me*******@disc ussions.microso ft.com> wrote in message
news:F2******** *************** ***********@mic rosoft.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.DefaultVie w;

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

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

"melanieab" <me*******@disc ussions.microso ft.com> wrote in message
news:CE******** *************** ***********@mic rosoft.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(n ew object[]{nodeF.Item(i). Attributes["ID"].Value, ...});

where nodeF is the xmlNodeList = xml.GetElements ByTagName("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.co m
>
> "melanieab" <me*******@disc ussions.microso ft.com> wrote in message
> news:F2******** *************** ***********@mic rosoft.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
1095
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 location ... cellValue = windowHandle.inch(y, x) Now, I have to pull out the attributes (MSB) ...
2
1988
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 CurrentCellChanged works unless I want the row which has a cell selected and I click on that cell, obvious answer click another cell in that row, but I have to code for stupid users! I tried the click event but that didn't work, maybe I was doing something wrong....
2
2217
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 setting that tell the process that the new top of the document region is now at the end of the last block-container used, this must be set in that last block container. 3. find the value used in the 'top" setting on the prior
4
35620
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 displayed in a text box no matter which cell index I provide. I tried a row of code that successfully displays the rowindex of the selected row. The code with comments is below:
2
1606
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 might contain in the background. I've tried getting to get the text through the datagrid's control
2
4767
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. For example, when the user type something on a cell, I want to display what he wrote on another place in my application. I don't care if this text isn't going to be used finally (a.k.a, if the user cancel the editing mode).
8
4690
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 ) { var totoalCartons = 0; var row = document.getElementById( 'oceanDeliveries' ).rows;
1
3001
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: =+'H:\QC\2007\Quarter 1\EC\Risk Measures'!F14 and paste value it. I'm using Ms. Excel 2000. Procedures: 1) Choose the Source_Directory and Source_Name
2
3323
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 the the cells of the table respectively which I have done easily but the problem is when I add the dynamically generated dropdownlist to the cell I cannot read the value from the dropdownlist. For adding the dropdownlist in the cell I have done the...
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9484
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9957
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8983
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.