ChrisHunter 152 Posting Whiz in Training Featured Poster

That did it thanks for you help

ChrisHunter 152 Posting Whiz in Training Featured Poster

Well spotted on the line 9. thanks i'll have a crack with your suggestion. any other suggestions are welcome

ChrisHunter 152 Posting Whiz in Training Featured Poster

Hi, i'm trying to implement a print function and i can print a single string out but i'm having trouble configuring the page setup properly, mainly moving to a new line when the margin of the page is reached and moving to a new lines for each string in a list of string.

so far i have this printing out a single piece of text:

private void document_PrintPage(object sender,
        System.Drawing.Printing.PrintPageEventArgs e)
        {
            System.Drawing.Font printFont = new System.Drawing.Font
            ("Arial", 28, System.Drawing.FontStyle.Regular);

            string text = "Now then";
            // Draw the content.
            e.Graphics.DrawString(text.ToString(), printFont, System.Drawing.Brushes.Black, 10, 10);
        }

i've tried looking on the internet but musent be using the right search criteria because i can only find stuff to print one small string.

Any suggestions of how to do the above or suggestions of tutorials will be great

thanks

ChrisHunter 152 Posting Whiz in Training Featured Poster

Have a look through this I've just done the same function and it helped alot.

ChrisHunter 152 Posting Whiz in Training Featured Poster

Thanks for you help, i figured it out and used the split method heres my code:

private void showAllRecords()
    {
        //gets entered ID 
        int recID = Integer.parseInt(textField6.getString());
        try
        {
            byte[] Details = new byte[frs.getRecordSize(recID)];
            // Gets record using entered ID
            Details = frs.getRecord(recID);
            // Calls split() and stores vextor returned by split()
            String[] splitStr = split( new String (Details));
            // Uses array index to store appropreate array value in textField
            textField3.setString(splitStr[0]);
            textField4.setString(splitStr[1]);
            textField5.setString(splitStr[2]);                
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
    

    // Split a string with symblo, return vecotr
    private String[] split(String original)
    {
        Vector nodes = new Vector();
        String separator = ",";
        // Parse nodes into vector
        int index = original.indexOf(separator);
        while(index>=0)
        {
            nodes.addElement( original.substring(0, index) );
            original = original.substring(index+separator.length());
            index = original.indexOf(separator);
        }
        // Get the last node
        nodes.addElement( original );
        // Create string array with segments of split string
        result = new String[nodes.size()];
        if( nodes.size()>0 )
        {
            for(int loop=0; loop<nodes.size(); loop++)
            {
            result[loop] = (String)nodes.elementAt(loop);
            }
        }
    return result;
    }

Some of the comments may be wrong but code works.

ChrisHunter 152 Posting Whiz in Training Featured Poster

i've never used a tokeniser before so i dont know what delimited is. However there is a space between s and H and also between r and 2.

I get the string from a record store and need to tokenise it after its been retreived.

sorry if my description is a little vague i dont have much experience with record stores or tokenising

thanks

Chris

ChrisHunter 152 Posting Whiz in Training Featured Poster

Hi my problem is that i'm making a mobile app and i need to seperate the following string:

ChrisHunter21

into:

Chris
Hunter
21

What is the easiest way to do this in J2ME ?

i had a look at the Ostermiller one but didnt understand it.

Thanks Chris

ChrisHunter 152 Posting Whiz in Training Featured Poster

Hi,

At the moment i'm trying to locate xml files to use their content. I would like to be able find all files that have a particular pattern in their name (for example student_James.xml; student_Chris.xml so "student" would be the pattern). I want to be able to do this using a drive that is selected from a comboBox (i've figured out how to get a list of all possivle drives).

As only the drive and name pattern is known (not the full directort), i want to be able to locate the files using only the drive and the name pattern.

Any help would be greatly appreciated

Thanks

Chris

ChrisHunter 152 Posting Whiz in Training Featured Poster

The Value of dtForm of the column is definatly DateTime. For some reason the column values are formatted like so '000-00-00 00:00:00.000', but will only accept '000-00-00' when updating the column values.

I don't know what the issue is, if it was a format issue it wouldn't allow such a value to be stored in the first place would it ?

I'm okay just storing '000-00-00' for now but would like to know the solution if possible.

Thank you for your help so far.

ChrisHunter 152 Posting Whiz in Training Featured Poster

Hi i keep getting an exception when i'm trying to update table values within a database. the exception is below but i dont change from datetime to varchar it always stay as datetime.

is there any other reasons why this is happening ?

"The conversion of a varchar data type to a datetime data type resulted in an out-of-range value."

objtyp.dtForm  = Convert.ToDateTime(reader["dtFrom"]);

public DateTime dtForm
{
   get;
   set;
}

string SQL = "UPDATE TABLE_NAME SET dtFrom = '" + objtyp.dtForm + "' WHERE ObjectTypeID = 1";

Thanks

Chris

ChrisHunter 152 Posting Whiz in Training Featured Poster

I managed set the attributes of the property grid manually using an example off the internet a while ago and its working fine.

What i was wondering was how do i create the property grid attributes using the column names from a batabase table rather than setting them myself (columns may change so manually creating attributes means they cannot be changed without going into the code)

for example i might have two object obj1 with Name; Area and diameter attributes and obj2 with Name; Ares and Number of Sides attributes. The two objects have different attributes so manually setting them would result in redundent attributes.

Sorry i am fairly rubbish at explaining this.

ChrisHunter 152 Posting Whiz in Training Featured Poster

Would the formula not be

result = (value1 / 100) * value2;

value2 is the persentage you want

ChrisHunter 152 Posting Whiz in Training Featured Poster

Can you be so kind to clarify?

I've managed to set the value of the private variables, it was just due to my inexperience with C#.

I idealy wanted the attributes to be automatucally changed depending on the selected object as attributes differ from object to object.

For the sake of my project I have created the property grid as shown above but if you know how the attributes can be automatically set depending on the selected object that would be great.

Thanks for your help it's much appreciated.

ChrisHunter 152 Posting Whiz in Training Featured Poster

Hi, Could anyone tell me the best way to implement a propertygrid?

currently I'm doing it like this but I'm having truble setting the value of the private variable with the values returned but a single SqlDataReader:

[DefaultPropertyAttribute("ObjectTypeID")]
    public class ObjectType
    {

        private int _objTypeID;
        private int _stateType;
        private int _state;

        [CategoryAttribute("Object State Defaults"), DescriptionAttribute("Object type ID")]
        public int ObjectTypeID
        {
            get
            {
                return _objTypeID;
            }
            set
            {
                _objTypeID = value;
            }
        }

        [CategoryAttribute("Object State Defaults"), DescriptionAttribute(" state type of Object type")]
        public int StateType
        {
            get
            {
                return _stateType;
            }
            set
            {
                _stateType = value;
            }
        }

        [CategoryAttribute("Object State Defaults"), DescriptionAttribute("state of object type")]
        public int State
        {
            get
            {
                return _state;
            }
            set
            {
                _state = value;
            }
        }
}

Thanks in advanced

Chris

ChrisHunter 152 Posting Whiz in Training Featured Poster

Hi

i need to add a combo box to a property grid that can be populated with the result of an sql statement, i can more than likely populate it when i come to it but i have no idea how to add the combo box.

Currently i am creating the items in my property grid which just need to be a textfield like so:

private int _objTypeID;

        [CategoryAttribute("Object State Defaults"), DescriptionAttribute("Object type ID")]        
        public int ObjectTypeID
        {
            get
            {
                return _objTypeID;
            }
            set
            {
                _objTypeID = value;
            }
        }

But i have no idea how to add combo boxes to it.
Any help is much appreciated.

Thanks in advanced

Chris

ChrisHunter 152 Posting Whiz in Training Featured Poster

Hi I'm pritty new to C# I'm having trouble with items repeating in a combo box

This method gets the values from my table and stores it in the list of strings which it does fine . . . I think.

public class EditStates {
        public List<string> getStates(CEditStates ced)
        {
            string typeSelected = (string)ced.cb1.SelectedItem;
            string states = "SELECT State FROM MyTables.StateDefaults 
            WHERE ObjectTypeID = '" + typeSelected + "'";
            SqlCommand cmd = new SqlCommand(states, db.Connect());
            SqlDataReader reader;

            List<string> objStates = new List<string>();
            try
            {
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    objStates.Add(reader["State"].ToString());           
                }
                reader.Close();
            }
            catch
            {
                MessageBox.Show("Failed to retreive object states");
            }
            return objStates;
        }
   }

And this method changes the value of cbo2 and populates cbo3 (which has the repeated values) when cbo1 is changed.

public class CEditeStates {
        private void cbo1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string newobjDesc = ed.getNewDesc(this);
            getObjectTypeState() method

            List<string> _objState = ed.getStates(this);
            if (cbo2.SelectedItem != null && cbo3.Items == null)
            {
                if (cbo2.SelectedItem.ToString() != newobjDesc)
                {
                    cboB2.SelectedItem = newobjDesc;

                    foreach (string str in _objState)
                    {
                        cbo3.Items.Add(str);
                    }
                }
            }
       }
   }

Can anyone see why cbo3 repeats the values ?
Thanks in advance