Database

Simon4VB

Member
Joined
Apr 2, 2009
Messages
23
Programming Experience
1-3
I have created a datagrid, the first column ID was set to DataGridViewButtonColumn, so in the column ID there is a button with an ID (ez Joe) in the field. I also have a picturebox1 and a seperate textbox1
In the Private Sub DataGridView1_CellContentClick I wrote the following

PictureBox1.Image = Image.FromFile("C:\Users\Simon\Desktop\" + TextBox1.Text + ".jpg")

Therefore when I write Joe in a seperate textbox and press the button in the datagridview Joe's image shows up in a seperate picturebox

I have tried
PictureBox1.Image = Image.FromFile("C:\Users\Simon\Desktop\" + PartNoDataGridViewTextBoxColumn.text + ".jpg")

So that when I press the button with ID Joe on it the picture shows up in PictureBox1. Instead of writing ID Joe in a seperate textbox. But it does not work.

What am I doing wrong. I am using VS2005

Thanks in advance for your help.
 
What does the Text property of PartNoDataGridViewTextBoxColumn actually contain? Have you checked? Is the Text property of that column even what you actually want? Is the Text of the column going to change depending on what button you click? Obviously not. You will need to specify the row somehow for that, won't you?
 
When your button is clicked, you can find the current row. In this example I assume a DataSet name of MyDataSet, a datatable name of MyDataTable and a bindingsource of MyDataTableBindingSource. You must adjust the names according to your context:

VB.NET:
Dim ro as MyDataTableRow = DirectCast(DirectCast(MyDataTableBindingSource.Current, DataRowView).Row, MyDataTableRow)

'now you can access properties of the current row
Dim imgPath as String = "C:\whatever\" & ro.PartNo & ".jpg"

DO NOT USE + for string concatenation, use &
 
Of course it isn't. That's just example code. We don;t know what your actual types are called so we use place-holders. You're supposed to replace that with with your actual DataRow type.
 
When your button is clicked, you can find the current row. In this example I assume a DataSet name of MyDataSet, a datatable name of MyDataTable and a bindingsource of MyDataTableBindingSource. You must adjust the names according to your context:

VB.NET:
Dim ro as MyDataTableRow = DirectCast(DirectCast(MyDataTableBindingSource.Current, DataRowView).Row, MyDataTableRow)

'now you can access properties of the current row
Dim imgPath as String = "C:\whatever\" & ro.PartNo & ".jpg"

DO NOT USE + for string concatenation, use &



"Hwa is thet mei thet hors wettrien the him self nule drinken" ;)
 
Back
Top