DateTimePicker Control in DataGrid

K

Ken

Dear all,
I have read the article in
http://www.msdn.microsoft.com/msdnmag/issues/03/08/DataGri
ds/toc.asp?frame=true
I copy the idea of creating the DataGridComboBoxColumn to
DateTimePickerColumn.
Everything just fine but the SetColumnValueAtRow.
The original article can update the value of the datagrid
but my version can't. Here are the code of the original:
----------------------------------------------------------
-
private void comboBox_Leave(object
sender, EventArgs e)
{
System.Data.DataRowView rowView =
(System.Data.DataRowView) this.comboBox.SelectedItem;
string s = (string) rowView.Row
[this.comboBox.DisplayMember];
System.Diagnostics.Debug.WriteLine
(String.Format("Leave: {0} {1}", this.comboBox.Text, s));
this.SetColumnValueAtRow(this.cm,
this.iCurrentRow, s);
this.Invalidate();

this.comboBox.Hide();

this.DataGridTableStyle.DataGrid.Scroll -= new
EventHandler(this.DataGrid_Scroll);
}
protected override void
SetColumnValueAtRow(System.Windows.Forms.CurrencyManager
source, int rowNum, object value)
{
System.Diagnostics.Debug.WriteLine
(String.Format("SetColumnValueAtRow {0} {1}", rowNum,
value));
object s = value;


System.Windows.Forms.CurrencyManager cm =
(System.Windows.Forms.CurrencyManager)
(this.DataGridTableStyle.DataGrid.BindingContext
[this.comboBox.DataSource]);

System.Data.DataView dataview =
((System.Data.DataView)cm.List);

int i=0;
int j=dataview.Count;

for(i=0; i < j; i++)
{
if (s.Equals(dataview
[this.comboBox.DisplayMember]))
break;
}

if(i<j)
s = dataview
[this.comboBox.ValueMember];
else
s = DBNull.Value;

base.SetColumnValueAtRow (source,
rowNum, s);
}
---------------------------------------------------------
below is my version:
private void dt_CloseUp(object sender,
EventArgs e)
{
DateTime s = this.dt.Value;
this.SetColumnValueAtRow(this.cm,
this.iCurrentRow,s);
this.Invalidate();
}
protected override void
SetColumnValueAtRow(CurrencyManager source, int rowNum,
object value)
{
base.SetColumnValueAtRow(source,
rowNum, value);
}
----------------------------------------------------------
-
Those user controls use different components, and I can't
figure out the DataBindings from ComboBox to
DateTimePicker. Therefore I am not sure which DataBinding
should be bind to DataGrid.BindContext.
Does any one can help?
THANKS ALOT.
Ken
P.S. The original article is helpful and very clear. Must
have a glance.
 
D

Dmitriy Lapshin [C# / .NET MVP]

Ken,

Look at this example of the DateTimePickerColumn:

http://groups.google.com/[email protected]&rnum=8

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Ken said:
Dear all,
I have read the article in
http://www.msdn.microsoft.com/msdnmag/issues/03/08/DataGri
ds/toc.asp?frame=true
I copy the idea of creating the DataGridComboBoxColumn to
DateTimePickerColumn.
Everything just fine but the SetColumnValueAtRow.
The original article can update the value of the datagrid
but my version can't. Here are the code of the original:
----------------------------------------------------------
-
private void comboBox_Leave(object
sender, EventArgs e)
{
System.Data.DataRowView rowView =
(System.Data.DataRowView) this.comboBox.SelectedItem;
string s = (string) rowView.Row
[this.comboBox.DisplayMember];
System.Diagnostics.Debug.WriteLine
(String.Format("Leave: {0} {1}", this.comboBox.Text, s));
this.SetColumnValueAtRow(this.cm,
this.iCurrentRow, s);
this.Invalidate();

this.comboBox.Hide();

this.DataGridTableStyle.DataGrid.Scroll -= new
EventHandler(this.DataGrid_Scroll);
}
protected override void
SetColumnValueAtRow(System.Windows.Forms.CurrencyManager
source, int rowNum, object value)
{
System.Diagnostics.Debug.WriteLine
(String.Format("SetColumnValueAtRow {0} {1}", rowNum,
value));
object s = value;


System.Windows.Forms.CurrencyManager cm =
(System.Windows.Forms.CurrencyManager)
(this.DataGridTableStyle.DataGrid.BindingContext
[this.comboBox.DataSource]);

System.Data.DataView dataview =
((System.Data.DataView)cm.List);

int i=0;
int j=dataview.Count;

for(i=0; i < j; i++)
{
if (s.Equals(dataview
[this.comboBox.DisplayMember]))
break;
}

if(i<j)
s = dataview
[this.comboBox.ValueMember];
else
s = DBNull.Value;

base.SetColumnValueAtRow (source,
rowNum, s);
}
---------------------------------------------------------
below is my version:
private void dt_CloseUp(object sender,
EventArgs e)
{
DateTime s = this.dt.Value;
this.SetColumnValueAtRow(this.cm,
this.iCurrentRow,s);
this.Invalidate();
}
protected override void
SetColumnValueAtRow(CurrencyManager source, int rowNum,
object value)
{
base.SetColumnValueAtRow(source,
rowNum, value);
}
----------------------------------------------------------
-
Those user controls use different components, and I can't
figure out the DataBindings from ComboBox to
DateTimePicker. Therefore I am not sure which DataBinding
should be bind to DataGrid.BindContext.
Does any one can help?
THANKS ALOT.
Ken
P.S. The original article is helpful and very clear. Must
have a glance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top