|
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 | |
Share:
|
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 | | |
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
| | |
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
| | |
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 > > | | |
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 > > | | |
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 > > > > > > > | | This discussion thread is closed Replies have been disabled for this discussion. Similar topics
reply
views
Thread by Brian Alexander |
last post: by
|
2 posts
views
Thread by Graham Y |
last post: by
|
2 posts
views
Thread by TadPole |
last post: by
|
4 posts
views
Thread by Neil |
last post: by
|
2 posts
views
Thread by niceguy |
last post: by
|
2 posts
views
Thread by news.microsoft.com |
last post: by
|
8 posts
views
Thread by ipy2006 |
last post: by
| | | | | | | | | | | | |