Binding Data

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a windows form with 5 fields. They are bound as follows:

drvDetail = (DataRowView) cm.Current;
vueDetail = drvDetail.DataView;

this.BindingContext[vueDetail].Position = cm.Position;

txtSON.DataBindings.Add("Text", vueDetail, "service-order-number");
txtTaskID.DataBindings.Add("Text", vueDetail, "taskid");
txtServiceDesc.DataBindings.Add("Text", vueDetail, "task-desc");
txtStartDate.DataBindings.Add("Text", vueDetail, "start-date");
txtStartTime.DataBindings.Add("Text", vueDetail, "start-time");
txtCompDate.DataBindings.Add("Text", vueDetail, "complete-date");
txtCompTime.DataBindings.Add("Text", vueDetail, "complete-time");
txtServiceCost.DataBindings.Add("Text", vueDetail, "task-cost");

The problem is I fill in the field data as follows:

LoadData();
cbServices.DataSource = dvServices;
cbServices.DisplayMember = "service-description";
cbServices.ValueMember = "service-nbr";

The data appears in the text box ok, but when I save it the fields are null.
If I key in the data its works just fine, what am I doing wrong?? Please
Help!!!
 
Norm,

What do you mean with "save"

You show us the databinding setting for textboxes and a combobox, but not
how you "save" the data.

Cor
 
--
Norm Bohana


Cor Ligthert said:
Norm,

What do you mean with "save"

You show us the databinding setting for textboxes and a combobox, but not
how you "save" the data.

Cor

nbohana said:
I have a windows form with 5 fields. They are bound as follows:

drvDetail = (DataRowView) cm.Current;
vueDetail = drvDetail.DataView;

this.BindingContext[vueDetail].Position = cm.Position;

txtSON.DataBindings.Add("Text", vueDetail, "service-order-number");
txtTaskID.DataBindings.Add("Text", vueDetail, "taskid");
txtServiceDesc.DataBindings.Add("Text", vueDetail, "task-desc");
txtStartDate.DataBindings.Add("Text", vueDetail, "start-date");
txtStartTime.DataBindings.Add("Text", vueDetail, "start-time");
txtCompDate.DataBindings.Add("Text", vueDetail, "complete-date");
txtCompTime.DataBindings.Add("Text", vueDetail, "complete-time");
txtServiceCost.DataBindings.Add("Text", vueDetail, "task-cost");

******************* WHAT I LEFT OUT *************************
if (this.ShowDialog() == DialogResult.OK)
cm.EndCurrentEdit();
else
cm.CancelCurrentEdit();
***************************************************

******************* THIS IS THE UPDATE CODE ****************
private void Update_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.OK;
}

**************************************************************
 
nbohana,

That is in my opinion still no save, don't you have somewhere a
dataadapter.update in your program.

I am curious how you fill the data.

Cor
 
I will try to explain. I have a popup winform with 6 textbox's that is used
to collect the data to be saved. I populate these textbox's with the data
from the combo box data. Then I use the update code to place the data in a
datagrid. And then it gets saved. The problem comes about when the data goes
to the datagrid, the data that is keyed into a textbox is fine, but the
generated data that goes to the datagrid is null. Its like nothing was in the
textbox! I hope the helps.
 
Sorry, I"m really having trouble following what is going. You are using the
word 'update', and it's not clear what the means.

It sounds like you have more then one data source, that is really holding
the same data.

You can bind a grid, and textboxes, to the same datatable. The datarow can
show the summary for each row, and the textboxes can show the details for
the currently selected row.

Also, you should be able to debug into your code to see exactly what values
the textboxes have, what values you are putting into your other data source,
etc. You should be able to just use the debugger to figure out where the
problem is occurring.
 
I am sorry about the confusion, I just choose the wrong words. What I am
trying to do is fill the data fields in a datagrid. I use a windows form with
several text boxes that are bound to the datagrid fields. The problem is in
the win form textbox fields. If I key in the data everything is ok. When I
use the datetimepicker or combo box to enter data into the textbox fields it
displays ok, but when I trandfer it to the datagrid there is no data
transfered. The data is bound as follows:

drvDetail = (DataRowView) cm.Current;
vueDetail = drvDetail.DataView;

this.BindingContext[vueDetail].Position = cm.Position;

txtSON.DataBindings.Add("Text", vueDetail, "service-order-number");
txtTaskID.DataBindings.Add("Text", vueDetail, "taskid");
txtServiceDesc.DataBindings.Add("Text", vueDetail, "task-desc");
txtStartDate.DataBindings.Add("Text", vueDetail, "start-date");
txtStartTime.DataBindings.Add("Text", vueDetail, "start-time");
cbStatus.DataBindings.Add("Text", vueDetail, "task-status");
txtCompDate.DataBindings.Add("Text", vueDetail, "complete-date");
txtCompTime.DataBindings.Add("Text", vueDetail, "complete-time");
txtServiceCost.DataBindings.Add("Text", vueDetail, "task-cost");

if (this.ShowDialog() == DialogResult.OK)
cm.EndCurrentEdit();

******** The DataGrid *********************

DataGridTableStyle tbl = new DataGridTableStyle();
tbl.MappingName = "details";
DataGridTextBoxColumn col;
col = new DataGridTextBoxColumn();
col.MappingName = "taskid";
col.HeaderText = "Task ID";
col.Alignment = HorizontalAlignment.Center;
col.Width = 60;
tbl.GridColumnStyles.Add(col);
col = new DataGridTextBoxColumn();
col.MappingName = "task-desc";
col.HeaderText = "Service Description";
col.Alignment = HorizontalAlignment.Center;
col.Width = 85;
tbl.GridColumnStyles.Add(col);
col = new DataGridTextBoxColumn();
col.MappingName = "start-date";
col.HeaderText = "Scheduled Start Date";
col.Alignment = HorizontalAlignment.Center;
col.Width = 85;
tbl.GridColumnStyles.Add(col);
col = new DataGridTextBoxColumn();
col.MappingName = "start-time";
col.HeaderText = "Scheduled Start Time";
col.Alignment = HorizontalAlignment.Center;
col.Width = 85;
tbl.GridColumnStyles.Add(col);
col = new DataGridTextBoxColumn();
col.MappingName = "task-status";
col.HeaderText = "Task Status";
col.Alignment = HorizontalAlignment.Center;
col.Width = 85;
tbl.GridColumnStyles.Add(col);
col = new DataGridTextBoxColumn();
col.MappingName = "complete-date";
col.HeaderText = "Completion Date";
col.Alignment = HorizontalAlignment.Center;
col.Width = 70;
tbl.GridColumnStyles.Add(col);
col = new DataGridTextBoxColumn();
col.MappingName = "complete-time";
col.HeaderText = "Completion Time";
col.Alignment = HorizontalAlignment.Center;
col.Width = 80;
tbl.GridColumnStyles.Add(col);
col = new DataGridTextBoxColumn();
col.MappingName = "task-cost";
col.HeaderText = "Service Cost";
col.Alignment = HorizontalAlignment.Right;
col.Width = 90;
tbl.GridColumnStyles.Add(col);
grdTasks.TableStyles.Add(tbl);

Norm Bohana
 
Back
Top