Show JPG image

Hi everyone,

I first would like to warn you that I'm a newbie programmer. So if I have left out important code for you guys to determine what I'm doing wrong, let me know.

I am making a PocketPC application using C# and an XML file as a database. I would like to display the corresponding JPG image in a PictureBox, or somewhere on the main page.

A sample of my xml file. The bolded line is the picture reference.


 <fragenkatalog>

<ca_id >4</ ca_id>

<ca_titel>head ap</ca_titel>

<ca_bildurl1>kopf_ap.jpg</ca_bildurl1>

<ca_disabled>0</ca_disabled>

<ca_alter>999</ca_alter>

<ca_sex>n</ca_sex>

</fragenkatalog>




This is what I have, which doesn't work.

//Bind image to picturebox

ca_bildurl.DataBindings.Add("Image",dt,"ca_bildurl1");


The ID is chosen from a ListBox, and the corresponding data is displayed on the screen.

Any help would be appreciated! Thanks!

M.


Answer this question

Show JPG image

  • akka

    How did you get the XML loaded into the DataTable

  • Tony128

    It's a listbox ( - is that what you mean ) 
  • firstfruits

    code shown below


  • aleph

    This may be an error on your part via typing but I noticed the following:

    <ca_id >4</ ca_id>

    There's a space between "</" and "ca_id>".



  • jeremymarx

    Looks like you finally got an answer on this thread: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=190980&SiteID=1.

    Persistence pays

     

     


  • force_fx

    But it looks to me like ca_id is an object. Is it a control or DataTable/DataSet

  • bazinou

    What is dt Where is the DataSource

  • Jason Presley

    (just wanted to add that your website is very nice.  :) )
  • Tolis Carpenter

     SpeBeeTo wrote:
    (just wanted to add that your website is very nice.  :) )

    Thanks!



  • KirillA

    // Create a new dataset.

    fragenkatalogDS = new DataSet();

     

    // Set the Locale for the DataSet,

    // using the current culture as the default

    fragenkatalogDS.Locale = CultureInfo.CurrentCulture;string xmlFileName;

    //

    // Set file names and create file streams.

    // The XSD, XML, and EXE must be in the same directory.

    xmlFileName = "\\Program Files\\SmartDeviceApplication1\\fragenkatalog.xml";

    xsdFileName = "\\Program Files\\SmartDeviceApplication1\\fragenkatalog.xsd";

    FileStream FsXML = new FileStream(xmlFileName,FileMode.Open);

    FileStream FsXSD = new FileStream(xsdFileName,FileMode.Open);

    // Load the schema into the DataSet.

    XmlTextReader xtrXSD = new XmlTextReader(FsXSD);

    fragenkatalogDS.ReadXmlSchema(xtrXSD);

    xtrXSD.Close();

    FsXSD.Close();

    // Load the data into the DataSet.

    XmlTextReader xtrXML = new XmlTextReader(FsXML);

    fragenkatalogDS.ReadXml(xtrXML);

    xtrXML.Close();

    FsXML.Close();

    // Get a DataTable to conveniently use for binding.

    DataTable dt = fragenkatalogDS.Tables["fragenkatalog"];

    //Bind the list box to abbreviations of the states.

    ca_id.DataSource = dt;

    ca_id.DisplayMember = "ca_titel";

     

    //Bind the label to show the name of the state.

    ca_titel.DataBindings.Add("Text",dt,"ca_titel");

    ca_alter.DataBindings.Add("Text",dt,"ca_alter");

    ca_sex.DataBindings.Add("Text",dt,"ca_sex");

    //This works fine with labels and text. 

    //Bind image to picturebox

    //maybe use a imagelist

    ca_bildurl.DataBindings.Add("Text",dt,"ca_bildurl1");

    }

    //I used this as a sort of "template" for the picturebox. 

     

    // ca_titel

    //

    this.ca_titel.Font = new System.Drawing.Font("Tahoma", 9.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))));

    this.ca_titel.Location = new System.Drawing.Point(0, 8);

    this.ca_titel.Size = new System.Drawing.Size(240, 24);

    this.ca_titel.Text = "ca_titel";

    this.ca_titel.TextAlign = System.Drawing.ContentAlignment.TopCenter;

    //

    // ca_bildurl

    //

    this.ca_bildurl.Location = new System.Drawing.Point(0, 88);

    this.ca_bildurl.Size = new System.Drawing.Size(168, 176);

    //this.ca_bildurl.Image = "ca_bildurl1";

    //Error message I receive when this is being compiled:  Cannot implicitly convert type 'string' to 'System.Drawing.Image'

    //I have also tried something like this after i added the actual image to the resources:

    //this.ca_bildurl.Image = ((System.Drawing.Image)(resources.GetObject("ca_bildurl1.Image")));


     

     

     

    Update.  Worked on the file a little over the holidays.  I think I'm closer, but not sure.  :S

     

    The bolded parts are the references to the picturebox.  I get only one error message, and that's the Cannot implicitly convert type 'string' to 'System.Drawing.Image'.

     

    Basically what I'm thinking is that I want to say, "For this picturebox 'jpg' image path, use the text found in 'ca_bildurl1' in the xml file for this particular id. It worked so far for the text/labels. The images are located in the same directory as the other files. 

    Any ideas   Thanks again!


  • Michel Jongbloed

    // Get a DataTable to conveniently use for binding.

    DataTable dt = fragenkatalogDS.Tables["fragenkatalog"];

    //Bind the list box to abbreviations of the states.

    ca_id.DataSource = dt;

    ca_id.DisplayMember = "ca_id";

    //Bind the label to show the name of the state.

    ca_titel.DataBindings.Add("Text",dt,"ca_titel");

    ca_alter.DataBindings.Add("Text",dt,"ca_alter");

    ca_sex.DataBindings.Add("Text",dt,"ca_sex");

    //Bind image to picturebox

    //maybe use a imagelist

    ca_bildurl.DataBindings.Add("Text",dt,"ca_bildurl1");

    }


  • lilphish

     SpeBeeTo wrote:

    // Get a DataTable to conveniently use for binding.

    DataTable dt = fragenkatalogDS.Tables["fragenkatalog"];

    //Bind the list box to abbreviations of the states.

    ca_id.DataSource = dt;

    ca_id.DisplayMember = "ca_id";

    //Bind the label to show the name of the state.

    ca_titel.DataBindings.Add("Text",dt,"ca_titel");

    ca_alter.DataBindings.Add("Text",dt,"ca_alter");

    ca_sex.DataBindings.Add("Text",dt,"ca_sex");

    //Bind image to picturebox

    //maybe use a imagelist

    ca_bildurl.DataBindings.Add("Text",dt,"ca_bildurl1");

    }

    Can you paste the error message please

    Also, what is ca_id



  • dev15`4534345677

     Chris Lovett wrote:

    Persistence pays

     

     

    Certainly does.  And thanks everyone for helping newbies like me! 


  • subdigital

    Thanks for that info, it was an error of my typing.  The code itself doesn't have that. 

     

    I really don't have an error message, it's just I don't know how to get the picture to show up in the picturebox.

     

    ca_id is the ID #.


  • Show JPG image