Thank you. That helped. by doing this in CurrencyManager.CurrentChanged
event, I have the correct picture diplaying.
private void cm_CurrentChanged(object sender, EventArgs e)
{
DataRow dr = ((DataRowView)cm.Current).Row;
if (dr["arrow"].ToString() == "D")
this.arrow.ImageIndex = 1;
else
this.arrow.ImageIndex = 0;
}
Is there any way that I can put this code in the DataBindings, advanced
section in the designer and therefore not have to write an event handler?
Somewhere I thought that we could use expressions. In short, how do you bind
to a property that does not match the datatype of the column? In this
example I want to set an integer based on a column that is a string. In
other cases I want to set the visible property (a bool) based on the value in
a string column.
Hi Aurin,
Thanks for your feedback.
Sorry, I do not think I understand your point. In my last reply, I did not
use CurrencyManager.CurrentChanged, so I do not know what this event does.
It seems that you want to bind one type of datasource to another type of
property, yes? For this, we can use DataBinding.Parse and Format events to
do the type conversion, sample code like this:
DataTable dt=null;
private void Form1_Load(object sender, System.EventArgs e)
{
dt=new DataTable();
dt.Columns.Add("column1", typeof(int));
dt.Columns.Add("column2", typeof(string));
for(int i=0;i<5;i++)
{
DataRow dr=dt.NewRow();
dr["column1"]=i;
dr["column2"]=i.ToString();
dt.Rows.Add(dr);
}
//We bind int type property to string type column
this.myPictureBox1.DataBindings.Add("ImageIndex", dt, "column2");
this.myPictureBox1.DataBindings[0].Format+=new
ConvertEventHandler(Form1_Format);
this.myPictureBox1.DataBindings[0].Parse+=new
ConvertEventHandler(Form1_Parse);
}
//Convert column string data to int type and pass to the property
private void Form1_Format(object sender, ConvertEventArgs e)
{
if(e.DesiredType==typeof(int))
{
e.Value=Int32.Parse((string)e.Value);
}
}
//Parse property int data to string type and update the underlying
datasource
private void Form1_Parse(object sender, ConvertEventArgs e)
{
if(e.DesiredType==typeof(string))
{
e.Value=e.Value.ToString();
}
}
private void button1_Click(object sender, System.EventArgs e)
{
this.myPictureBox1.DataBindings[0].BindingManagerBase.Position++;
}
=========================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Aurin - 21 Jun 2005 14:45 GMT
I'm sorry but I don't see how using format/parse will work. Suppose I want
to do either of the following. How would I code the parse event?
If string-value = D or S or M
display image 0
else
display image 1
or this:
if string-column is null
visible = false
else
visible = true
> Hi Aurin,
>
[quoted text clipped - 60 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
"Jeffrey Tan[MSFT]" - 22 Jun 2005 03:09 GMT
Hi Aurin,
Thanks for your feedback.
For your first scenario, I do not think it is reasonable. DataBinding will
not allow several datasource value to be mapped into single UI content.
This is because Winform databinding is 2 ways. We can map "D" or "M" or "S"
to 0 without any problem, however, how can we map 0 or 1 property value
back to datasource? Should we map 0 property value back to "D" or "M" or
"S"? We can not determine this, so this is not a reasonable scenario for
databinding. We should use databinding for 1-to-1 mapping.
Hope this helps
====================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
"Jeffrey Tan[MSFT]" - 24 Jun 2005 06:31 GMT
Hi Aurin,
Does my reply make sense to you? If you still have any concern, please feel
free to tell me, thanks
Best regards,
Jeffrey Tan
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.