all groups > dotnet windows forms databinding > june 2005 >
You're in the

dotnet windows forms databinding

group:

bindingContext.AddNew not working with binded Combobox in form


Re: bindingContext.AddNew not working with binded Combobox in form Rashmi
6/6/2005 8:13:47 PM
dotnet windows forms databinding:
Are you trying to do something similar to this example:
http://www.fawcette.com/vsm/2002%5F01/magazine/features/abrust/

I normally create a dataview - and bind it to grid. For adding a new
record - dataview.addnew().

Hope this helps,
Rashmi
bindingContext.AddNew not working with binded Combobox in form Jaime
6/6/2005 9:13:11 PM
Hi All,

I have a form with a datagrid, several textboxes and one combobox,
representing the detailed of whatever is selected in the datagrid. All the
textboxes and combo are binded like:

textBox.DataBindings.Add( "text", ds, "field1" );

.... now I have one combobox that is binded like this
textBox.DataBindings.Add( "SelectedIndex", ds, "field2" );

the combo box is setup like:

combo.Items.AddRange( new object[] { "opt1", "opt2" } );
combo.Name = "whaterver";
.... (other display proerties)

Now, here's the thing. When I tray to add a new record through
BindingContext[...].AddNew(), a new record is added in the DataGrid but the
current position is not moved to that record and the contents off all the
textboxes is not cleared...

I've read that a checkbox in a form can cause this problem (a bug) but I
haven't found a way to work arround thisone, I haven't found this exact
problem either though.

Any ideas?

Thanks


Re: bindingContext.AddNew not working with binded Combobox in form Jaime
6/6/2005 10:39:19 PM
Yes that's more or less it... I have a datagrid that is bound to a dataset,
that is filled with a dataadapter, now the dataadapter contains all the
commands for select, insert, delete, update. Then the textboxes (that show
the detailed record that is selected in the datagrid) are also bounded using
the same dataset. I'm not using a dataview, just the dataadapter and the
dataset. Now if I don't bind the combo box, everything works fine, but as
soon as I bind it, the problem shows up

Thanks for your answer


[quoted text, click to view]

Re: bindingContext.AddNew not working with binded Combobox in form Rashmi
6/7/2005 6:36:28 AM
To move to the newly added row you could do something like this:
i = dataset.Tables(tablename).Rows.Count
DataGrid1.CurrentCell = New DataGridCell(i, 0)

Also, Is the combobox bound to any datasource ?
Re: bindingContext.AddNew not working with binded Combobox in form Rashmi
6/7/2005 6:41:29 AM
To move to the newly added row you could do something like this:
i = dataset.Tables(tablename).Rows.Count
DataGrid1.CurrentCell = New DataGridCell(i, 0)

Also, Is combobox bound to any datasource?

-Rashmi
Re: bindingContext.AddNew not working with binded Combobox in form Rashmi
6/7/2005 6:48:05 AM
Sorry, I did not read your first post carefully. For binding the combo
boxes you can try using "SelectedValue" property , Eg:
combobox.DataBindings.Add("SelectedValue", dataset, "fieldname")
AddThis Social Bookmark Button