How do i access BindingSource current row ?

How do i access BindingSource current row and change value of specific field ?

I have client table with 4 elements

client_guid
code
name
surname

My form is binded through BindingSource to all fields except client_guid

I want to create new client. So i enter values in all fields and hit save. But i get error that client_guid should be supplied.

I useBindingSource.AddNew() and then i use BindingSource.EndEdit() to save new clients - this works fine and new row is created, but it works only if i also bind client_guid to some textbox... sure it is not what i want. I wan to assign client_guid value in code not from UI textbox

I can't get it how do i access this client_guid field to set it's value. I would do it before calling EndEdit()

i thought i can access it like BindingSource.Current, but there are no methods for that. Then i thought maybe i should set value directly in DataSet but that does not work either - it says there are no rows at position 0.

This is code in short:

physicalPersonBindingSource.DataSource =CommonData.MainDataManager.DataSetCR.PhysicalPerson;

physicalPersonBindingSource.AddNew();

textBoxCode.DataBindings.Add("Text", physicalPersonBindingSource,"code",true,DataSourceUpdateMode.OnPropertyChanged,String.Empty);

textBoxName.DataBindings.Add("Text", physicalPersonBindingSource,"name",true,DataSourceUpdateMode.OnPropertyChanged,String.Empty);

textBoxSurname.DataBindings.Add("Text", physicalPersonBindingSource,"surname",true,DataSourceUpdateMode.OnPropertyChanged,String.Empty);

physicalPersonBindingSource.EndEdit();

[3193 byte] By [MixfromLatvia] at [2007-12-22]
# 1
The datatable has an TableNewRow event. I would assign the client_guid a new guid there.
KenTucker at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 2

1. That would be a solution i think, but it does not answer my question... is it realy true, that i can't set this value without using event ?

2. How do i access this TableNewRow event ... is it possible through designer or, i have generate DataSetCR.cs class and do it there ?

I guess you meant something like this:

public MainDataManager()

{

_dataSetCR.PhysicalPerson.TableNewRow += new System.Data.DataTableNewRowEventHandler(PhysicalPerson_TableNewRow);

}

private void PhysicalPerson_TableNewRow(object sender, EventArgs e)

{

DataSetCR.PhysicalPersonRow physicalPersonRow = (DataSetCR.PhysicalPersonRow)sender;

DataSetCR.ClientRow clientRow =

(DataSetCR.ClientRow)(physicalPersonRow.GetParentRow("FK_PhysicalPerson_Client"));

physicalPersonRow.client_guid = clientRow.client_guid;

}

MixfromLatvia at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 3

Ok, no need to answer i got it. I could do it also this way:

((DataSetCR.PhysicalPersonRow)physicalPersonBindingSource.Current).client_guid = client.ClientGuid

MixfromLatvia at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 4

I tried the posted code pattern without success. The reason is: BindingSource.Current is of DataRowView type. But this one worked for me:

int id = Convert.ToInt32(((dtsMy.TblRow)((DataRowView)tblBindingSource.Current).Row).ID);

I hope it will help somebody! Wink

AlexanderYarushin at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...