Retrieving Value from Grid in Master Detail Relationship

C

Christopher Weaver

I'm having the hardest time doing the simplest thing.

I have a DataGrid bound to a table in a master detail DataRelation within a
DataSet

relTaskActivities = new DataRelation("TaskActivities", parentCol, childCol);
dsTaskActivities.Relations.Add(relTaskActivities);
dgActivity.SetDataBinding(dsTaskActivities, "Tasks.TaskActivities");

This works fine. I have a properly behaving master detail relationship.
But now I need to retrieve the value of a specific column in the current row
(the one selected by the user) from the detail side. I've created a
CurrencyManager to obtain the row:

cActivityMgr = (CurrencyManager)this.BindingContext[dsTaskActivities,
"Tasks.TaskActivities"];

And I've used it to select the current row:
int ThisRow = cActivityMgr.Position;
string richNote =
dsTaskActivities.Tables["Activity"].Rows[ThisRow]["Note"].ToString();

I'm getting the contents of the desired column but not the current row. It
appears to be selecting the row without regard to the master detail
relationship. How do I get the proper index of the selected row within the
grid?

Thanks.
 
B

Bart Mermuys

Hi,
inline

Christopher Weaver said:
I'm having the hardest time doing the simplest thing.

I have a DataGrid bound to a table in a master detail DataRelation within
a DataSet

relTaskActivities = new DataRelation("TaskActivities", parentCol,
childCol);
dsTaskActivities.Relations.Add(relTaskActivities);
dgActivity.SetDataBinding(dsTaskActivities, "Tasks.TaskActivities");

This works fine. I have a properly behaving master detail relationship.
But now I need to retrieve the value of a specific column in the current
row (the one selected by the user) from the detail side. I've created a
CurrencyManager to obtain the row:

cActivityMgr = (CurrencyManager)this.BindingContext[dsTaskActivities,
"Tasks.TaskActivities"];

And I've used it to select the current row:
int ThisRow = cActivityMgr.Position;
string richNote =
dsTaskActivities.Tables["Activity"].Rows[ThisRow]["Note"].ToString();

You can get the selected row (DataRowView) directly from the CurrencyManager
:

DataRowView activityDRV =
(DataRowView)this.BindingContext[dsTaskActivities,
"Tasks.TaskActivities"].Current;

string richNote = (string)activityDRV["Note"];


HTH,
greeetings
 
C

Christopher Weaver

Thanks for writing back, but I must say that I've never read a more terse or
vague response. Nevertheless, I scratched my head for a while a concluded
that the only possible meaning that I could attribute to your answer in the
context of my question was that the grid itself must have the properties I'm
looking for.

I looked again at the DataGrid in the help system and realized that I had
been looking at the wrong entry. What a difference a few properties can
make.

For anyone listening in the working code looks like this:

int ThisRow = dgActivity.CurrentRowIndex;
string richNote = dgActivity[ThisRow, 1].ToString();

Where 1 is the index of the column I'm looking for.




Bart Mermuys said:
Hi,
inline

Christopher Weaver said:
I'm having the hardest time doing the simplest thing.

I have a DataGrid bound to a table in a master detail DataRelation within
a DataSet

relTaskActivities = new DataRelation("TaskActivities", parentCol,
childCol);
dsTaskActivities.Relations.Add(relTaskActivities);
dgActivity.SetDataBinding(dsTaskActivities, "Tasks.TaskActivities");

This works fine. I have a properly behaving master detail relationship.
But now I need to retrieve the value of a specific column in the current
row (the one selected by the user) from the detail side. I've created a
CurrencyManager to obtain the row:

cActivityMgr = (CurrencyManager)this.BindingContext[dsTaskActivities,
"Tasks.TaskActivities"];

And I've used it to select the current row:
int ThisRow = cActivityMgr.Position;
string richNote =
dsTaskActivities.Tables["Activity"].Rows[ThisRow]["Note"].ToString();

You can get the selected row (DataRowView) directly from the
CurrencyManager :

DataRowView activityDRV =
(DataRowView)this.BindingContext[dsTaskActivities,
"Tasks.TaskActivities"].Current;

string richNote = (string)activityDRV["Note"];


HTH,
greeetings
I'm getting the contents of the desired column but not the current row.
It appears to be selecting the row without regard to the master detail
relationship. How do I get the proper index of the selected row within
the grid?

Thanks.
 
B

Bart Mermuys

Hi,

Christopher Weaver said:
Thanks for writing back, but I must say that I've never read a more terse
or vague response.

What's so vague about it, i mean you yourself said you can get the position
out of a CurrencyManager, but the position didn't match the DataTable,
because a grid is never directly bound to a DataTable or DataSet but to a
DataView.

Then i said, you can directly get the current DataRowView from the
CurrencyManager like this:

DataRowView activityDRV =
(DataRowView)this.BindingContext[dsTaskActivities,
"Tasks.TaskActivities"].Current;

Once you have the current DataRowView you can get the value for an
individual cell, like:

string richNote = (string)activityDRV["Note"];

I don't know what more i could have told you.
Nevertheless, I scratched my head for a while a concluded that the only
possible meaning that I could attribute to your answer in the context of my
question was that the grid itself must have the properties I'm looking for.

Really ? All i said was that the CurrencyManager keeps the current row
which happens to be a DataRowView.
I looked again at the DataGrid in the help system and realized that I had
been looking at the wrong entry. What a difference a few properties can
make.

For anyone listening in the working code looks like this:

int ThisRow = dgActivity.CurrentRowIndex;
string richNote = dgActivity[ThisRow, 1].ToString();

The way i showed you works, but if you prefer the above, no problem, it's
just another way.

Where 1 is the index of the column I'm looking for.




Bart Mermuys said:
Hi,
inline

Christopher Weaver said:
I'm having the hardest time doing the simplest thing.

I have a DataGrid bound to a table in a master detail DataRelation
within a DataSet

relTaskActivities = new DataRelation("TaskActivities", parentCol,
childCol);
dsTaskActivities.Relations.Add(relTaskActivities);
dgActivity.SetDataBinding(dsTaskActivities, "Tasks.TaskActivities");

This works fine. I have a properly behaving master detail relationship.
But now I need to retrieve the value of a specific column in the current
row (the one selected by the user) from the detail side. I've created a
CurrencyManager to obtain the row:

cActivityMgr = (CurrencyManager)this.BindingContext[dsTaskActivities,
"Tasks.TaskActivities"];

And I've used it to select the current row:
int ThisRow = cActivityMgr.Position;
string richNote =
dsTaskActivities.Tables["Activity"].Rows[ThisRow]["Note"].ToString();

You can get the selected row (DataRowView) directly from the
CurrencyManager :

DataRowView activityDRV =
(DataRowView)this.BindingContext[dsTaskActivities,
"Tasks.TaskActivities"].Current;

string richNote = (string)activityDRV["Note"];


HTH,
greeetings
I'm getting the contents of the desired column but not the current row.
It appears to be selecting the row without regard to the master detail
relationship. How do I get the proper index of the selected row within
the grid?

Thanks.
 
C

Christopher Weaver

My Dear Friend,

I am laughing out loud right now. I didn't read your entire post! At the
top you wrote 'Hi, inline.' and I took that to be your response --- all of
your response.

Having just read the rest of what you posted, I must say there was nothing
vague about it at all. Thank you again for your help! And I promise to
never fail to read an entire post!

Christopher Weaver




Bart Mermuys said:
Hi,

Christopher Weaver said:
Thanks for writing back, but I must say that I've never read a more terse
or vague response.

What's so vague about it, i mean you yourself said you can get the
position out of a CurrencyManager, but the position didn't match the
DataTable, because a grid is never directly bound to a DataTable or
DataSet but to a DataView.

Then i said, you can directly get the current DataRowView from the
CurrencyManager like this:

DataRowView activityDRV =
(DataRowView)this.BindingContext[dsTaskActivities,
"Tasks.TaskActivities"].Current;

Once you have the current DataRowView you can get the value for an
individual cell, like:

string richNote = (string)activityDRV["Note"];

I don't know what more i could have told you.
Nevertheless, I scratched my head for a while a concluded that the only
possible meaning that I could attribute to your answer in the context of
my question was that the grid itself must have the properties I'm looking
for.

Really ? All i said was that the CurrencyManager keeps the current row
which happens to be a DataRowView.
I looked again at the DataGrid in the help system and realized that I had
been looking at the wrong entry. What a difference a few properties can
make.

For anyone listening in the working code looks like this:

int ThisRow = dgActivity.CurrentRowIndex;
string richNote = dgActivity[ThisRow, 1].ToString();

The way i showed you works, but if you prefer the above, no problem, it's
just another way.

Where 1 is the index of the column I'm looking for.




Bart Mermuys said:
Hi,
inline

I'm having the hardest time doing the simplest thing.

I have a DataGrid bound to a table in a master detail DataRelation
within a DataSet

relTaskActivities = new DataRelation("TaskActivities", parentCol,
childCol);
dsTaskActivities.Relations.Add(relTaskActivities);
dgActivity.SetDataBinding(dsTaskActivities, "Tasks.TaskActivities");

This works fine. I have a properly behaving master detail
relationship. But now I need to retrieve the value of a specific column
in the current row (the one selected by the user) from the detail side.
I've created a CurrencyManager to obtain the row:

cActivityMgr = (CurrencyManager)this.BindingContext[dsTaskActivities,
"Tasks.TaskActivities"];

And I've used it to select the current row:
int ThisRow = cActivityMgr.Position;
string richNote =
dsTaskActivities.Tables["Activity"].Rows[ThisRow]["Note"].ToString();

You can get the selected row (DataRowView) directly from the
CurrencyManager :

DataRowView activityDRV =
(DataRowView)this.BindingContext[dsTaskActivities,
"Tasks.TaskActivities"].Current;

string richNote = (string)activityDRV["Note"];


HTH,
greeetings


I'm getting the contents of the desired column but not the current row.
It appears to be selecting the row without regard to the master detail
relationship. How do I get the proper index of the selected row within
the grid?

Thanks.
 
B

Bart Mermuys

Hi,

Christopher Weaver said:
My Dear Friend,

I am laughing out loud right now. I didn't read your entire post! At the
top you wrote 'Hi, inline.' and I took that to be your response --- all of
your response.

Yeah that's funny, I can imagine that if you only read "inline" that it was
extremely vague :)
Having just read the rest of what you posted, I must say there was nothing
vague about it at all. Thank you again for your help! And I promise to
never fail to read an entire post!

Fair enough.

Greetings
Christopher Weaver




Bart Mermuys said:
Hi,

Christopher Weaver said:
Thanks for writing back, but I must say that I've never read a more
terse or vague response.

What's so vague about it, i mean you yourself said you can get the
position out of a CurrencyManager, but the position didn't match the
DataTable, because a grid is never directly bound to a DataTable or
DataSet but to a DataView.

Then i said, you can directly get the current DataRowView from the
CurrencyManager like this:

DataRowView activityDRV =
(DataRowView)this.BindingContext[dsTaskActivities,
"Tasks.TaskActivities"].Current;

Once you have the current DataRowView you can get the value for an
individual cell, like:

string richNote = (string)activityDRV["Note"];

I don't know what more i could have told you.
Nevertheless, I scratched my head for a while a concluded that the only
possible meaning that I could attribute to your answer in the context of
my question was that the grid itself must have the properties I'm looking
for.

Really ? All i said was that the CurrencyManager keeps the current row
which happens to be a DataRowView.
I looked again at the DataGrid in the help system and realized that I
had been looking at the wrong entry. What a difference a few properties
can make.

For anyone listening in the working code looks like this:

int ThisRow = dgActivity.CurrentRowIndex;
string richNote = dgActivity[ThisRow, 1].ToString();

The way i showed you works, but if you prefer the above, no problem, it's
just another way.

Where 1 is the index of the column I'm looking for.




Hi,
inline

I'm having the hardest time doing the simplest thing.

I have a DataGrid bound to a table in a master detail DataRelation
within a DataSet

relTaskActivities = new DataRelation("TaskActivities", parentCol,
childCol);
dsTaskActivities.Relations.Add(relTaskActivities);
dgActivity.SetDataBinding(dsTaskActivities, "Tasks.TaskActivities");

This works fine. I have a properly behaving master detail
relationship. But now I need to retrieve the value of a specific
column in the current row (the one selected by the user) from the
detail side. I've created a CurrencyManager to obtain the row:

cActivityMgr = (CurrencyManager)this.BindingContext[dsTaskActivities,
"Tasks.TaskActivities"];

And I've used it to select the current row:
int ThisRow = cActivityMgr.Position;
string richNote =
dsTaskActivities.Tables["Activity"].Rows[ThisRow]["Note"].ToString();

You can get the selected row (DataRowView) directly from the
CurrencyManager :

DataRowView activityDRV =
(DataRowView)this.BindingContext[dsTaskActivities,
"Tasks.TaskActivities"].Current;

string richNote = (string)activityDRV["Note"];


HTH,
greeetings


I'm getting the contents of the desired column but not the current
row. It appears to be selecting the row without regard to the master
detail relationship. How do I get the proper index of the selected
row within the grid?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top