I'm making a program that showing my data into image and label. Here's an example of my program when not clicked:
When not Clicked:
When Clicked
The question is when I click one of those images. How to show the id ("id_movie" in my SQL) of that image into a MessageBox ViewModel Class.
public class VModel
{
public VModel()
{
Clicked = new ClickedCommand(this);
DataTable dt = new DataTable();
using (MySqlConnection connection = new MySqlConnection("SERVER=localhost;" + "DATABASE=library;" + "UID=root;" + "PASSWORD=;"))
{
MySqlDataAdapter adapter = new MySqlDataAdapter();
adapter.SelectCommand = new MySqlCommand("Select * from movie_list", connection);
adapter.Fill(dt);
}
Library = dt.DefaultView;
}
public ICommand Clicked { get; set; }
public DataView Library { get; private set; }
}
Click Class
internal class ClickedCommand : ICommand
{
private VModel vModel;
public ClickedCommand(VModel vModel)
{
this.vModel = vModel;
}
public event EventHandler CanExecuteChanged { add { } remove { } }
public bool CanExecute(object parameter)
{
return true;
}
public void Execute(object parameter)
{
MessageBox.Show("the id that got clicked");
}
}
If you just need the data of the database, you could give the
dt
as a parameter when initializing theClickedCommand
.And in the
Execute
method you access thevModel
orLibrary
field, depending on what you gave as a parameter and present the data.