I have a DataTable filled with records from my Employee table. I did not create a DataSource in the project for this Employee table. I simply created a command and data adapter in code to fill the dataset.
I have an Employee form with a BindingSource set to my dataset and I connected a BindingNavigation control to the BindingSource. Of course, I have a number of textboxes, checkboxes, and comboboxes bound to the BindingSource. I can navigate thru the records fine and delete and update data too.
The problem is that I can't add records. I can click the add new button on the navigation bar and it shows the record count going up, but it won't let me navigate to those new records. If I try to click the move last button, it doesn't move me to any record at all. If I close the form and open it back up, then I see that the new blank record is there, and I can navigate to it.
What am I missing Why can't I navigate to the new record immediately
If I create a DataSource for the project and drag it to a form, the navigation works just fine. When I click the add new button it moves me to a new record and clears the fields so I can start typing data.
How can I make it work without using a DataSource I define at the Project level
Thanks for any help you can give!

AddNew() creates a new row but I can't navigate to it
Jagan P
Are your control bindings binding through the binding source or directly to the dataset I tried a simple repro - add the following code to your form's constructor after InitializeComponent call:
DataTable dt = new DataTable("Table1");
dt.Columns.Add("one", typeof(int));
dt.Columns.Add("two", typeof(string));
dt.Rows.Add(5, "one");
DataSet ds = new DataSet("dataset1");
ds.Tables.Add(dt);
BindingSource bs = new BindingSource(ds, "Table1");
BindingNavigator bn = new BindingNavigator(bs);
TextBox textBox1 = new TextBox();
TextBox textBox2 = new TextBox();
this.Controls.AddRange(new Control[] { textBox1, textBox2, bn });
textBox1.Dock = DockStyle.Top;
textBox2.Dock = DockStyle.Top;
textBox1.DataBindings.Add("Text", bs, "one", true);
textBox2.DataBindings.Add("Text", bs, "two", true);
-mark
Program Manager
Microsoft
This post is provided "as-is"
jlewis99
John Ferguson
Through a bindingSource.
...
SqlCommand command = new SqlCommand("SELECT * from myTable;", connection);
command.CommandType = CommandType.Text;
adapter.SelectCommand = command;
// Fill the DataSet.
dataSet_test = new DataSet("test");
adapter.Fill(dataSet_test);
connection.Close();
this.bindingSource1.DataSource = dataSet_test;
this.bindingSource1.DataMember = "myTable";
this.bindingNavigator1.BindingSource = this.bindingSource1;
this.dataGridView1.DataSource = this.bindingSource1;
Mr. Furious
That did the trick. Thanks ronnyh.
dataSet1.Tables[
"Employees"].Columns["Active"].DefaultValue = true;Rob Sumsion
Thanks....I got the answer...
After looking thru some other entries in the forum, I realized that my problem was that I was binding checkboxes to the BindingSource. You have to set the DefaultValue of the bit field in the datatable before binding the checkbox to the BindingSource.
Once I set the DefaultValue everything worked just like it should.