Problem in Binding Data to a Control?

mythinky

Member
Joined
Jun 4, 2004
Messages
20
Programming Experience
1-3
1. How to bind a picture box to a column in a database that contains the image's path (url)?
2. How to manipulate the format of the string?
How to manipulate the format of the string before it is display in the text box. The text box is using data binding. I think if we don't use binding data then, it will be simple and easy to manipulate the string.
But the problem will raise if we using the data binding. How to manipulate the string in a binded data text box?

Thanks in advance for those contribute their time to read this and give some solution to this problem.
Your idea will be appreciated. Please provide the code.
 

mythinky

Member
Joined
Jun 4, 2004
Messages
20
Programming Experience
1-3
tlkerns said:
Check out the Binding.Format and Binding.Parse events in the Visual Studio help.

Tony



I still get confused with the Binding.Parse means? Would you mind to help me about this problem? Is Binding.Parse able to parse an URL of the picture?
Thanks a bunch...
 

tlkerns

Member
Joined
Jun 3, 2004
Messages
19
Programming Experience
3-5
Binding.Format is where you format your data from the database prior to displaying it to your user. For instance, a database value of 1.2 can be displayed as $1.20.

Binding.Parse is just the opposite. It "unformats" the displayed value prior to writing it back to the data source. As in the previous example, it would remove the $.

These events are very powerful. You can do pretty much anything with data values prior to displaying them. Possibly even converting a path to a picture.

Tony
 

mythinky

Member
Joined
Jun 4, 2004
Messages
20
Programming Experience
1-3
Problem converting path to a picture

I have tried it out, but i still having problem convert the path to a picture.
How can i solve this problem?
Please provide the code example.
Special Thanks to Toni...
 

tlkerns

Member
Joined
Jun 3, 2004
Messages
19
Programming Experience
3-5
I don't have anything to test this code on, but here's my best guess:

Dim b as Binding = New Binding("Image", MyDataSet.MyDataTable, "DataColumnImagePath")
AddHandler b.Format, AddressOf MyPictureBox_FormatImage
MyPictureBox.DataBindings.Add(b)

Private Sub MyPictureBox_FormatImage(ByVal sender as Object, ByVal e as ConvertEventArgs)
e.Value=Image.FromFile(e.Value.ToString)
End Sub

Note that even if this were to actually work, it does not provide any error handling. You would have to check for invalid or empty paths.

Tony
 

mythinky

Member
Joined
Jun 4, 2004
Messages
20
Programming Experience
1-3
tlkerns said:
I don't have anything to test this code on, but here's my best guess:

Dim b as Binding = New Binding("Image", MyDataSet.MyDataTable, "DataColumnImagePath")
AddHandler b.Format, AddressOf MyPictureBox_FormatImage
MyPictureBox.DataBindings.Add(b)

Private Sub MyPictureBox_FormatImage(ByVal sender as Object, ByVal e as ConvertEventArgs)
e.Value=Image.FromFile(e.Value.ToString)
End Sub

Note that even if this were to actually work, it does not provide any error handling. You would have to check for invalid or empty paths.

Tony


Thanks...
I have tried it out... I get an error here..........
Invalid cast from System.String to System.Drawing.Image
How could i get it works?
Please help me....
 
Top Bottom