1

What do you intend to do during the scan?
If you are looking for changes then you could use a FileSystemWatcher to do the "scanning" for you.

Votes + Comments
actually i want to scan my files in a directory after every 10 min.... thay why my own file allocation update its information.... because when a file is moved from one folder to other or it delete then my file allocation table must be updated for every in
0

@VIeditorlover: Not a bad solution but that alone will not fix the problem.

What I think is happening is :
[INDENT][I]NNExportDLL[/I] must wait for [I]ComputeNN[/I] to finish before it updates the GUI
This blocks the main thread from receiving the return value
which makes the GUI unresponsive.[/INDENT]

If the calling app is running this function on its UI thread then this will make things even more unresponsive.

0

Here is the same program again only using the [I]switch[/I] command mentioned by ddanbe.
This is very similar to using the [I]if - else if - else if [/I] of the previous program.
[CODE]static void Main(string[] args)
{
Console.Write("Enter a number: ");
int iNum = 0;
// read a value entered on the keyboard and converts it to a number
int.TryParse(Console.ReadLine().Trim(), out iNum);

switch (iNum)
{
    case 28:
        Console.WriteLine("Month is February");
        break;
    case 30:
        Console.WriteLine("Months are April ..."); // other month need to be added
        break;
    case 31:
        Console.WriteLine("Months are ..."); // add months
        break;
    default:
        Console.WriteLine("No months have that many days.");
        break;
}

Console.Write("Press any key to continue...");
Console.ReadKey();

}
[/CODE]

0

You all have missed the key point in the original question.
The fact that the OP is a [B]beginner[/B]!
Here is a basic program that demonstrates the use of the [I]if else[/I] command.
[CODE]static void Main(string[] args)
{
Console.Write("Enter a number: ");
int iNum = 0;
// read a value entered on the keyboard and converts it to a number
int.TryParse(Console.ReadLine().Trim(), out iNum);

if (iNum == 28)
{
    Console.WriteLine("Month is February");
}
else if (iNum == 30)
{
    Console.WriteLine("Months are April ..."); // other month need to be added
}
else if (iNum == 31)
{
    Console.WriteLine("Months are ..."); // add months
}
else
{
    Console.WriteLine("No months have that many days.");
}
Console.Write("Press any key to continue...");
Console.ReadKey();

}
[/CODE]

0

You can use the CellFormatting event to do this.
The following code snippet colours cells in the third column if they have a value of "-1".
[CODE] private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
var cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
if (e.ColumnIndex == 2 && ((string)cell.Value) == "-1")
{
e.CellStyle.ForeColor = Color.Red;
}
}[/CODE]
You must check the column index to ensure the test is applied to the right data value.

0

Line 57 is where the problem is.
Here you are directly referencing only the first PictureBox with index of j=0.
You need to convert [I]sender[/I] in to a picture box and use that instead.
Try this.
[CODE] if (System.IO.File.Exists(imgshow) && sender is PictureBox)
((PictureBox)sender).ImageLocation = imgshow;
[/CODE]
This adds a test to confirm that the sender is a PictureBox to prevent invalid cast errors.
Then cast sender to a PictureBox to set the new picture location.

0

If you intend to use the same [I]ContextMenu [/I]for each picture box then delcare the menu variable at form level instead of inside the button click handler.

To add a picture box at run time you create a new PictureBox object and add it to the form's (or other container's) [I]Controls [/I]collection after setting the [I]Size[/I],[I]Location [/I]and other properties.

To get an idea of how this is done, add a [I]PictureBox [/I]to your form, set some of the properties and save the form. Then look in the <formname>.designer.cs file for how the Form Designer codes this for you.

If you get stuck, just post your efforts and someone will help you.

0

You are not adding an event handler for the click event of the menu items.
You need to do something like this.
[CODE] private void button1_Click(object sender, EventArgs e)
{
int iCtr = 0;
ContextMenuStrip docmenu = new System.Windows.Forms.ContextMenuStrip();
DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
{
string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath);
//MessageBox.Show("Files found: " + files.Length.ToString(), "Message");
foreach (string imageFile in files)
{
ToolStripMenuItem openimg = new ToolStripMenuItem();
openimg.Text = imageFile;[COLOR="red"] //<-- imageFile is already a string![/COLOR]
openimg.Click += menuitem_Click; [COLOR="Green"]//<-- attach to click event handler[/COLOR]
iCtr++;[COLOR="red"] //<---????[/COLOR]
docmenu.Items.Add(openimg); [COLOR="Red"]//<-- use Add to add a single item[/COLOR]
}
pictureBox8.ContextMenuStrip = docmenu;
}
}

    // handle image context menu item click events
    private void menuitem_Click(object sender, EventArgs e)
    {
        ToolStripMenuItem item = sender as ToolStripMenuItem;
        // edit if not a toolstrip menu
        if (item == null)
            return;
        // do something with item
        // e.g. Open file based on filename in Text property
        MessageBox.Show(string.Format("Selected Image File = \"{0}\"", item.Text), "Item Selected");
    }[/CODE]
0

The objects in System.Xml.Link namespace are a little easier to user than the System.Xml namespace objects.
You will need to add a reference to System.Xml.Link in you project reference.

[CODE] private void load_xml2(string xml)
{
var xDoc = XDocument.Load(Application.StartupPath + "\RSS\" + xml + ".xml");

        // find channel element to append to (exit if not found)
        var channel = xDoc.Descendants("channel").ElementAt(0);
        if (channel == null)
            return;
        // create new item with sub tags
        var newItem = new XElement("item", 
            new XElement("title","New Item Title"),
            new XElement("description", "NEW ITEM"),
            new XElement("link", "Link to item"));
        // add new item to first channel
        channel.Add(newItem);

        xDoc.Save(Application.StartupPath + "\\RSS\\" + xml + "2.xml");
    }

[/CODE]

0

Even though you have created a new element on the document you need to add it to a node for it to be added to the document.

The following snippet should get you started.
[CODE] private void load_xml(string xml)
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(Application.StartupPath + "\RSS\" + xml + ".xml");

        // [COLOR="Green"]find channel element to append to[/COLOR]
        var channels = xDoc.GetElementsByTagName("channel", string.Empty);
        // if no channel tags then exit
        if (channels.Count==0)
            return;
        // create new item
        var newItem = xDoc.CreateElement("item");
        // [COLOR="Green"]add attributes (with value) [/COLOR]
        // [COLOR="Red"]Note: You do not have any attributes in your xml.[/COLOR]
        // [COLOR="Red"]This is added to show you how to do it and what the effect is.[/COLOR]
        newItem.SetAttribute("name", "NewItem");
        // [COLOR="green"]create and add item sub tags[/COLOR]
        var description = xDoc.CreateElement("description");
        description.InnerText = "NEW ITEM";
        newItem.AppendChild(description);
        // [COLOR="green"]add new item to first channel[/COLOR]
        channels[0].AppendChild(newItem);

        xDoc.Save(Application.StartupPath + "\\RSS\\" + xml + ".xml");
    }

[/CODE]

1

To use the [I]DataSource [/I]property of the data grid you must also bind any DataGridColumns you create to the columns of the data table. To do this you set the [I]DataPropertyName[/I] property to the name of the bound column in the data table.
If you do not do this then the data grid creates new columns for each column in the data table. (Perhaps this is why you cannot change the colours of the cells when using DataSource.)

Setting cell colours when using a DataSource is best done in the DataGrid.CellFormatting event as the data grid uses this to determine how to display the cell.
The snippet below changes the background for modified cells.
[CODE] private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
// get bound row for cell being formatted.
var drv = dataGridView1.Rows[e.RowIndex].DataBoundItem as DataRowView;

        // if row not bound then ignore it
        if (drv == null || drv.Row == null)
            return;

        // get local reference to row
        var row = drv.Row;

        // if row has original and current (new) value then test further
        if (row.HasVersion(DataRowVersion.Current) && row.HasVersion(DataRowVersion.Original))
        {
            // get original and current values
            object original = row[e.ColumnIndex, DataRowVersion.Original];
            object current = row[e.ColumnIndex, DataRowVersion.Current];
            // if original not same as current then change background colour of cell
            if (!current.Equals(original))
                e.CellStyle.BackColor = Color.PowderBlue;
        }
    }

[/CODE]

0

If you are still having trouble with this then you need to find out where the error is coming from.

If the debugger is not breaking in your code then you might benefit from trapping the first time exceptions. To do this use menu [I]Debug/Exceptions...[/I] then check [I]Common Language Runtime Exception[/I] to break when first thrown. Now when you debug your program it should break immediately the error occurs at the point in your code where it happens.

You should now try to fix the problem by understanding what causes it, then prevent it from happening.

For those occations when it is not possible to fix the problem then it is possible to trap the error using the [URL="

0

[QUOTE=x38class;1657465]Firstly, please use [CODE][/CODE] tags around your code.[/QUOTE]
In the forums here at Daniweb it is required that you put code tags around your code so that it is formatted as code.
(On your post you'll see that the administrator has kindly added the tags for you.)

It is not clear from the code you have posted where the problem might be.
Please post your code that handles the change in the drive selection on the list box.
Also, please post your original code again, but this time post the whole subroutine(s).

0

Click on your <DBname>.mdf (...\DB\emp.mdf) file in your project.
Look in the Properties view.
What is the value for the property "[I]Copy to Output Directory[/I]"?

If it is set to "Copy always" then every time you build your project the DB file in the Debug folder is overwritten!
This is probably why your data is apparently not saved between runs.