I want to set a value in a specific field in the current row of a DataSet.
This seems like the most basic thing to do but I can't find the syntax for
identifying the current row.
IOW, I can do this:
SomeRow["fieldName"] = 'value';
But how do I set SomeRow to the row that the user is currently viewing?
I tried this:
DataRowView drv = (DataRowView) cMgr.Current; //Where cMgr is a
CurrencyManager
drv["SubCategory"] = Value;
But it doesn't stick. When the user moves off the record and back again,
the previous value is restored. 3 2101
>> ... mightn't it be better to get them all into one
dataset and set up a DataRelation between them? <<
This is exactly what I needed to do. I'm still not used to this concept of
multiple tables residing in the same DataSet. ( I come from an environment
where DataSet and table were synonymous. )
Here's the idea. Tasks is a table with a Foreign Key constraint in
SubCategory. Since the user can only include items from the finite set of
choices within the referenced table, I am providing a ComboBox from which
they are constrained to make their choice. Furthermore, the items in that
ComboBox are constrained by the choice made in another field, also controled
by a ComboBox.
I've placed a TextBox on the form and bound its Text property to
"Tasks.SubCategory" for the purposes of debugging this situation.
I've brought all of the tables within the same DataSet and created three
relationships (1 : m in each case): Task : Activities, Category :
SubCategory, and Category : Task. The dropdown behavior now results in the
underlying table receiving the user's selection. It did require one line of
code in the
SelectionChangeCommitted event to help it along:
dsTaskActivities.Tables["Tasks"].Rows[cMgr.Position]["SubCategory"] =
Value;
But I still have a problem. As the user moves through the records of the
Task table, the ComboBox does not always show the correct value for the
field that it is bound to. Sometimes it does, but other times it just
reveals a blank. What's really odd is that it will show a blank on a
specific row when approached from one direction, say the previous row, but
when approached from the following row it shows the correct value.
So, I've made some progress, but I still need to figure out why the ComboBox
is not consistant. If you have any thoughts on this I would really
appreciate it.
Also, I must implement the same behavior in a DataGrid. One of the columns
needs to have a ComboBox in it. In other words, it needs to function like
the property editor pane when editing a property like BorderStyle. Do you
know how to do this?
Thanks for your help.
"Ian Griffiths [C# MVP]" <ia*************@nospam.nospam> wrote in message
news:O$**************@tk2msftngp13.phx.gbl... Sorry - I'm used to using strongly-typed datasets. With those, the DataSet exposes a property for each table, and the table provides an indexer that means you don't need to use Rows. I have a habit of forgetting that when going back to normal datasets...
As for your combobox, if I understand correctly, you've bound the Text property to one table, but you've got the DataSource of the same combobox bound to a different table. I'm not sure if that's a supported scenario to be honest.
cbSubCategoryLookUp.DataBindings.Add("Text", dsTaskActivities, "Tasks.SubCategory");
and
cbSubCategoryLookUp.DataSource = dsCatSubCats.Tables["Category"];
I'm not sure what the expected behaviour is when you've got two different currency managers trying to control the same value. (Which is ultimately what's going on here. The combobox will want to set the Text property to be whatever the currently selected item is, which will be an item from the dsCatSubCats.Tables["Category"] table, but you've also got a binding trying to set it to something from a different table altogether.)
At least that's how it looks to me. On the other hand it's late here, so I could have misread it. :)
What are you trying to achieve here? Is there some relation between the Category table in dsCatSubCats and the SubCategory table in dsTaskActivities? If so, mightn't it be better to get them all into one dataset and set up a DataRelation between them? But I'm not quite clear on what your goal is, so I'm not sure how best to solve the problem.
-- Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
"Christopher Weaver" <we*****@verizon.net> wrote in message news:eK*************@TK2MSFTNGP10.phx.gbl... Thanks for the reply.
I've tried a couple of things before and since your post. Here's my attempt to implement one of your suggestions:
Your suggestion was: myDataSet.MyTable[currencyMgr.Position]["field"] = someValue;
and my implementation was: dsTaskActivities.Tables["Tasks"][cMgr.Position]["SubCategory"] = Value;
The error message received was: Cannot apply indexing with [] to an expression of type 'System.Data.DataTable'
So I changed it to this: dsTaskActivities.Tables["Tasks"].Rows[cMgr.Position]["SubCategory"] = Value;
And added this: dsTaskActivities.Tables["Tasks"].Rows[cMgr.Position].EndEdit();
Now here's the real problem. I've realized through some experimentation that the problem lies in the specific control that I'm using. I'm using a ComboBox to allow the user to select a value from a foreign key table. When a selection is made, the selected value is revealed in a TextBox that I added for debugging purposes; so I know that the value is being set properly. When I leave the editted row and return, the new value is still in the TextBox but the ComboBox is showing another value. Sometimes it's the previous value, sometimes it's something else entirely. While I thought that I was having trouble getting the value selected by the user to stick, it appears that I'm really having trouble getting the ComboBox to show the current value. I've used the following:
cbSubCategoryLookUp.DataBindings.Add("Text", dsTaskActivities, "Tasks.SubCategory"); textBox2.DataBindings.Add("Text", dsTaskActivities, "Tasks.SubCategory");
And yet they don't always show the same value even though the ComboBox is bound to the table that holds the only values allowed in SubCategory and the only values that show up in the TextBox are selected from the ComboBox dropdown list. This is how the ComboBox is bound:
cbSubCategoryLookUp.DataSource = dsCatSubCats.Tables["Category"]; cbSubCategoryLookUp.DisplayMember = "CatSubCats.SubCategory";
Do you have any idea what I'm missing here?
Chris.
"Ian Griffiths [C# MVP]" <ia*************@nospam.nospam> wrote in message news:Oc**************@TK2MSFTNGP10.phx.gbl... Christopher Weaver wrote: I want to set a value in a specific field in the current row of a DataSet.
So the first thing to know is that the DataSet doesn't have any notion of a current row.
In fact strictly speaking, the DataSet doesn't have any notion of a row. It just contains a bunch of DataTables. And it's the DataTables that contain the rows. But a DataTable doesn't have any notion of a current row either, no more than a table in a relational database has a notion of a 'current' row.
Currency (in the sense of what is currently selected) is entirely a UI thing. It's managed by the currency manager in a Windows Forms applciation.
SomeRow["fieldName"] = 'value';
But how do I set SomeRow to the row that the user is currently viewing?
I tried this:
DataRowView drv = (DataRowView) cMgr.Current; //Where cMgr is a CurrencyManager drv["SubCategory"] = Value;
But it doesn't stick. When the user moves off the record and back again, the previous value is restored.
You mean that your changes aren't being stored in the DataTable?
In which case you've misdiagnosed the problem. You *are* successfully getting hold of the current row. The reason the changes aren't sticking is because you probably need to call EndEdit on the DataRowView.
In a Windows Forms app, edits are provisional until they are applied. There are a number of reasons. One is that it may only make sense to check constraints once all of the fields for a row have been entered, in which case there has to be some point at which you say 'done now!' to try and apply the changes.
Also, by convention, in most grid editing UIs in Windows, you can usually cancel out of your current row edit.
So the changes you make through the view are probably not sticking because the edit is being regarded as provisional, and you never try to finish the edit.
At least that's one possibility - try calling EndEdit on the DataRowView and see if that helps.
Alternatively, just get the Position from the CurrencyManager, and go straight to the DataTable object rather than going via the view. Something like:
myDataSet.MyTable[currencyMgr.Position]["field"] = someValue;
-- Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
Christopher Weaver wrote: Here's the idea. Tasks is a table with a Foreign Key constraint in SubCategory.
So a task has to belong to a subcategory? Or a subcategory has to belong to
a task. I'm trying to get my head around where the primary and foreign keys
are.
If I've understood correctly, one of the columns in Tasks is SubCategoryID
(or something like that), and a FK constraint requires this to correspond to
a row in the SubCategory table. So SubCategory : Tasks is a 1:Many
relation. Have I understood, or did I get it backwards?
I'm not sure because I don't see that one listed here:
I've brought all of the tables within the same DataSet and created three relationships (1 : m in each case): Task : Activities, Category : SubCategory, and Category : Task.
That implies that Tasks has an FK to Category, and that SubCategory also has
an FK to Category. I don't know what the relationship between Tasks and
SubCategory is though.
Since the user can only include items from the finite set of choices within the referenced table, I am providing a ComboBox from which they are constrained to make their choice. Furthermore, the items in that ComboBox are constrained by the choice made in another field, also controled by a ComboBox.
Does the combobox list tasks, subcategories, categories, or something else?
You've got two sets of criteria both constraining what appears in the
ComboBox then? How are you making that work? Are you setting a filter on
the view?
But I still have a problem. As the user moves through the records of the Task table, the ComboBox does not always show the correct value for the field that it is bound to. Sometimes it does, but other times it just reveals a blank. What's really odd is that it will show a blank on a specific row when approached from one direction, say the previous row, but when approached from the following row it shows the correct value.
That's really strange. I have to admit I've not seen that happen before.
I'm afraid I can't offer any suggestions as to what the problem might be
based on prior experience.
Also, I must implement the same behavior in a DataGrid. One of the columns needs to have a ComboBox in it. In other words, it needs to function like the property editor pane when editing a property like BorderStyle. Do you know how to do this?
I don't use the built-in DataGrid much, so I'll have to leave that for
someone else...
--
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
Thanks for wading through my previous effort. This one should do it.
Here's the structure, (and with apologies, I didn't design it and would love
to change it)
tblTasks has five Foreign Keys: Category, SubCategory, AssignBy, AssignTo,
and Status. I would like the user to be able to select these values from
ComboBoxes because I don't want them to have the option of inputting a value
that's not legal. There is also a relationship between Category and
SubCategory in that tblSubCategory has a Foreign Key, Category, to
tblCategory. AssignBy and AssignTo are both linked to tblNames.
So, each task, tblTask row, must have a Category, SubCategory, AssignBy,
AssignTo, and Status value that are found in their respective tables.
Would you recommend that all of these tables be included in one DataSet?
Presently I have four included: tblTask, tblActivity, tblCategory, and
tblSubCategory. tblActivity has a Foreign Key to tblTask, as their names
would imply. The activities for each task are displayed nicely in the
DataGrid that I've placed on the same form.
Regarding the DataGrid. You mentioned that you don't work with the built-in
DataGrid much; what are my other options? Are there other DataGrids
available or must we create our own?
I don't know what to make of the inconsistent behavior of the ComboBox Text
property as I move through the rows of the Task table. If you were to be
given an assignment like this, what approach would you take? Would you use
ComboBox?
Thanks again.
BTW, are you in England? My mother was born there.
"Ian Griffiths [C# MVP]" <ia*************@nospam.nospam> wrote in message
news:uE**************@TK2MSFTNGP15.phx.gbl... Christopher Weaver wrote: Here's the idea. Tasks is a table with a Foreign Key constraint in SubCategory.
So a task has to belong to a subcategory? Or a subcategory has to belong to a task. I'm trying to get my head around where the primary and foreign keys are.
If I've understood correctly, one of the columns in Tasks is SubCategoryID (or something like that), and a FK constraint requires this to correspond to a row in the SubCategory table. So SubCategory : Tasks is a 1:Many relation. Have I understood, or did I get it backwards?
I'm not sure because I don't see that one listed here:
I've brought all of the tables within the same DataSet and created three relationships (1 : m in each case): Task : Activities, Category : SubCategory, and Category : Task.
That implies that Tasks has an FK to Category, and that SubCategory also has an FK to Category. I don't know what the relationship between Tasks and SubCategory is though. Since the user can only include items from the finite set of choices within the referenced table, I am providing a ComboBox from which they are constrained to make their choice. Furthermore, the items in that ComboBox are constrained by the choice made in another field, also controled by a ComboBox.
Does the combobox list tasks, subcategories, categories, or something else?
You've got two sets of criteria both constraining what appears in the ComboBox then? How are you making that work? Are you setting a filter on the view? But I still have a problem. As the user moves through the records of the Task table, the ComboBox does not always show the correct value for the field that it is bound to. Sometimes it does, but other times it just reveals a blank. What's really odd is that it will show a blank on a specific row when approached from one direction, say the previous row, but when approached from the following row it shows the correct value.
That's really strange. I have to admit I've not seen that happen before. I'm afraid I can't offer any suggestions as to what the problem might be based on prior experience.
Also, I must implement the same behavior in a DataGrid. One of the columns needs to have a ComboBox in it. In other words, it needs to function like the property editor pane when editing a property like BorderStyle. Do you know how to do this?
I don't use the built-in DataGrid much, so I'll have to leave that for someone else...
-- Ian Griffiths - http://www.interact-sw.co.uk/iangblog/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: David |
last post by:
I know that identifying the user IP address with
HTTP_SERVER_VARS;
is reliant on the browser agent but I have stumpled upon the following
code which I have tried to understand but failed!
...
|
by: kristofvdw |
last post by:
Hi,
I have to treat a given text file, but haven't got a clue which
extended ASCII set it is using.
Opening the file in Windows' Notepad or in DOS, all accented letters
and symbols are wrong....
|
by: gssstuff |
last post by:
I have a piece of code I use to compare two identically structured
tables. There are 15+ sets of tables I am comparing. I am looking to
see what has changed between the "old" and "new" versions...
|
by: Don Riesbeck Jr. |
last post by:
I'm working on an application (OEM) using C# that utilizes input from a
keyboard, and USB Barcode Scanner. The scanner is a HID Keyboard device,
and input from it is sent to the system as if it...
|
by: Tapi |
last post by:
Hello,
I am using Visual SourceSafe to work on a project in a team of three.
I have created a Windows group caleed "Application_MO" on my machine and
added my Windows login to it.
However,...
|
by: Tapi |
last post by:
Hello,
I can easily get the Windows login of the current user on my machine by
using:
User_login = HttpContext.Current.User.Identity.Name()
However once, I copy the aspx and...
|
by: bwmbagus |
last post by:
I am getting a strange result from some standard code.
Anyone got any ideas??
The puzzle
I have a web service calling System.Environment.UserName etc to return the
user name from the server....
|
by: kevin43 |
last post by:
I reaaly need some help with this. I'm trying develop a method for listing possible duplicate vendors. The problem is I have tons of legacy vendors that need to be mapped to the current ERP. I...
|
by: Frankie |
last post by:
It appears that System.Random would provide an acceptable means through
which to generate a unique value used to identify multiple/concurrent
asynchronous tasks.
The usage of the value under...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |