Click here to Skip to main content
15,908,274 members
Please Sign up or sign in to vote.
4.33/5 (3 votes)
See more: , +
I've got a data bound detail form. That I want to dual use for a) listing all items, b) filtering to single set of items.

So the form has these items, an autogen ID (aID), another ID (bID) and some other data fields.

I've added a constructor overload to pass in the bID value, and I've added a query to the TableAdapter on the DataSet for this table, that returns values by that ID.

All that works, if I enter the data direct into to the table for example.

But if the user wants to enter a new record (using the add button of the BindingNavigator) I want to pre-fill the bID field with the value that was passed to form (if there was one), and then set that field to readonly so they can't bork things up.

But I just can't get it to work. I've tried the AddingNew, the CurrentChanged and the CurrentItemChanged events of the BindingSource...but none work. i.e. I've got:
serverIDTextBox.ReadOnly = false;
if (serverID != null)
    serverIDTextBox.Text = serverID.ToString();
    serverIDTextBox.ReadOnly = true;

in those events currently.

Ah just found, that if I've got data relating to bID already in the table, then everything works! If there are no records for bID then it doesn't:(

Very consfused...

1 solution

If you have a Join in the query, it's possible that the datasource automatically sets as read-only.

In that case, you may need to add a stored procedure to make the insertion of data.
Share this answer
cjb110 5-Aug-11 7:29am    
Can I tell if the datasource has been set to read-only? In pure SQL terms it shouldn't be.
Astolf 5-Aug-11 7:36am    
It shouldn't be, but sometimes happens.
Try to add new row in the datatable programatically and see what happens.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900