DdoubleD 315 Posting Shark

You cannot directly call a trigger from C#. What you might be able to do is:

1) Separate your trigger code into a stored procedure that can be called by the trigger, and also by the application (c#).

2) Do something from the application that would cause the DB to fire the trigger. This way is kind of kludgee way to do it.

sknake commented: thats how I would do it +6
DdoubleD 315 Posting Shark

Here is one fix:

bool bInSetUI = false;
        private void SetUI()
        {
            bInSetUI = true; // suspend CheckChanged event

            checkBox1.Checked = AppSet.acon;
            checkBox2.Checked = AppSet.addnew;
            textBox1.Text = AppSet.defNPC;
            checkBox3.Checked = AppSet.shoscr;
            checkBox4.Checked = AppSet.copscr;
            checkBox5.Checked = AppSet.savscr;
            textBox2.Text = AppSet.defpath;
            log.wtl("Interfejs zaktualizowany");

            bInSetUI = false; // resume CheckChanged event...
        }

        private void UpdateSettings(object sender, EventArgs e)
        {
            if (!bInSetUI)
            {
                AppSet.acon = checkBox1.Checked;
                AppSet.addnew = checkBox2.Checked;
                AppSet.defNPC = textBox1.Text;
                AppSet.shoscr = checkBox3.Checked;
                AppSet.copscr = checkBox4.Checked;
                AppSet.savscr = checkBox5.Checked;
                AppSet.defpath = textBox2.Text;
                log.wtl("Ustawienia zaktualizowane");
            }
        }
sknake commented: That was going to be my suggestion until you stole my thoughts :X +6
DdoubleD 315 Posting Shark

Try this:

// TO USE:
            // 1) include COM reference to Microsoft Excel Object library
            // add namespace...
            // 2) using Excel = Microsoft.Office.Interop.Excel;
            private static void Excel_FromDataTable(DataTable dt)
            {
                // Create an Excel object and add workbook...
                Excel.ApplicationClass excel = new Excel.ApplicationClass();
                Excel.Workbook workbook = excel.Application.Workbooks.Add(true); // true for object template???

                // Add column headings...
                int iCol = 0;
                foreach (DataColumn c in dt.Columns)
                {
                    iCol++;
                    excel.Cells[1, iCol] = c.ColumnName;
                }
                // for each row of data...
                int iRow = 0;
                foreach (DataRow r in dt.Rows)
                {
                    iRow++;

                    // add each row's cell data...
                    iCol = 0;
                    foreach (DataColumn c in dt.Columns)
                    {
                        iCol++;
                        excel.Cells[iRow + 1, iCol] = r[c.ColumnName];
                    }
                }

                // Global missing reference for objects we are not defining...
                object missing = System.Reflection.Missing.Value;

                // If wanting to Save the workbook...
                workbook.SaveAs("MyExcelWorkBook.xls",
                    Excel.XlFileFormat.xlXMLSpreadsheet, missing, missing,
                    false, false, Excel.XlSaveAsAccessMode.xlNoChange,
                    missing, missing, missing, missing, missing);

                // If wanting to make Excel visible and activate the worksheet...
                excel.Visible = true;
                Excel.Worksheet worksheet = (Excel.Worksheet)excel.ActiveSheet;
                ((Excel._Worksheet)worksheet).Activate();

                // If wanting excel to shutdown...
                ((Excel._Application)excel).Quit();
            }
ddanbe commented: Nice SPAM counter! +5
DdoubleD 315 Posting Shark

I don't think you should be remapping keys across the entire system, unless you are creating a key mapping program that the user is in complete control over, including the ability to restore all previous/normal key mappings.

Using the RegisterHotKey function won't work for you because it fails if the mapping is already defined.

There is no easy way to do this that I am aware of. In theory, you could subclass the OS message loop to capture these keys and then redirect the message (using SendMessage ) as some other function.

I know you indicated "without using hooks", but if you are still interested in doing this, here are some basic links and further discussion:

Basic discussion of .NET Subclassing and OS Message Queue...

Subclassing Forms and Controls...

Simple hook installation with windows handle...

Keyboard hook example using WM_HOTKEY

DdoubleD 315 Posting Shark

I was kind of in a hurry this morning and my internet connection has been flaky the last couple of days (real bad this morning). I posted that code without testing it, and there were a couple of logic errors as well as an important missing part in the handling of the CellValueChanged event handler.

I decided to clean up the code and make it just a tad more generic too. I have also commented the code and left a couple of original lines commented out where I dropped the "Country, Store, City" enum. You should be able to see it as only a slight change in the call to your SetPermission method parameters. I do not call the UpdatePermissions method in this code, but it sets up the values needed for your SetPermission method, with the minor exception of the dropped enum for "Country, Store, & City", which you can change to use the code you have.

The listBox1 control is just an output for testing that the datatable binding updated the values correctly...

Regardless of how you are binding data to the gridview, I think you should be able to accomplish your task by extracting what you need from this example:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PermissionType = ForumSolutions.DatabaseStuff.PermissionsTable.PermissionType;
using PermissionsTable = ForumSolutions.DatabaseStuff.PermissionsTable;

namespace ForumSolutions
{
    public partial class Form_DataGridView_PermissionsTable : Form
    {
        DataTable dt;
        const int iNoneCol = (int)PermissionType.None + 1; …
sknake commented: great post +5
DdoubleD 315 Posting Shark

There may be a more elegant way to do this, but here is the logic I applied in a small program to demonstrate one way to get and set the checked state when the user clicks the cell's checkbox:

// This event occurs before the cell's state is committed,
        // so you have to check the current value and then negate it
        // to get the proposed state change...
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int iCol = e.ColumnIndex;
            int iRow = e.RowIndex;

            if (dataGridView1.Rows[iRow].Cells[iCol].ValueType == typeof(bool))
            {
                if (dataGridView1.Rows[iRow].Cells[iCol].Value == null ||
                    (bool)dataGridView1.Rows[iRow].Cells[iCol].Value == false)
                {
                    dataGridView1.Rows[iRow].Cells[iCol].Value = true;
                }
                else
                {
                    dataGridView1.Rows[iRow].Cells[iCol].Value = false;
                }

            }
        }

        // Occurs when the value is changed...
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            int iCol = e.ColumnIndex;
            int iRow = e.RowIndex;
            if (iRow > -1 & iCol > -1)
            {
                if (dataGridView1.Rows[iRow].Cells[iCol].ValueType == typeof(bool))
                {
                    bool bChecked = (bool)dataGridView1.Rows[iRow].Cells[iCol].Value;
                }
            }
        }

I don't know what you are doing with your SetPermission, but according to what you stated you want to do, you can call that inside the dataGridView1_CellValueChanged event if that is what you want to do.

DdoubleD 315 Posting Shark

Hello

I have seen the following method syntax and I am trying to understand how this works/or doesn't:

public class MyClass
    {

       public MyClass();

        public MyClass(string param);
  }

There is no implementation of the methods (constructors) and class is not declared virtual either...
Is this something new in C# 3.0 ???

Any ideas???

Thank you

Perhaps you saw some C++ code that looks like this, which in its simplest form, is very similar in appearance. In C++, this is called forward declaration. C# does not allow forward declarations.

ddanbe commented: Nice observation. +5
DdoubleD 315 Posting Shark

If you don't mind that the thread will halt for 2 seconds, you can use Thread.Sleep(2000).

sknake commented: you got it +5
DdoubleD 315 Posting Shark

Demonstrates using .NET Remoting to broadcast to client subscribers. There are three parts:

1) Server.cs - for console app responsible for broadcasting messages (date/time stamp currently)
2) Client.cs - for console app that registers with server to subscribe to broadcasts
3) Agent.cs - class library that facilitates/eposes the interfaces for our client/server communication
To use, create the three project types defined above and include the appropriate code found in this snippet. In both the Server and Client projects, add references to the Agent.DLL project. Then, modify the IP address in the ClientClass's creation of the AbstractServer remoteObject to a string that represents your server's IP.

I began this experiment 2 - 3 weeks ago and have been waiting to perform static IP testing outside my LAN/LOCALMACHINE, but have not yet been able to. I decided to go ahead and comment the code, readying it for posting, while I was reading a very interesting and informative post titled "Peer to Peer Chat", which has nothing to do really with this snippet (LOL). Anyway, I have commented my code and am posting it as-is, but I think it should work over the internet.

Server broadcast events occur on a Timer (timer code aquired via a thread replied to by sknake--I love this guy's code!). The clients receive the broadcast by registering an event handler with the server (ClientEventHandler).

Communication/interfacing accomplished ia client adding a broadcast event handler (+= ClientEventHandler) …

DdoubleD 315 Posting Shark

When posting to Daniweb, try to be more specific with your question(s). Your post is very vague and doesn't really ask a question. If you have began coding and cannot get something specific to work, post (use CODE tags) the portion of code in question and indicate the error you are getting. If you have a specific question about something you haven't coded yet that you don't know how it's done (not the entire program) and you want to see an example, you can ask that too.

Cheers!

DdoubleD 315 Posting Shark

It wasn't clear to me whether your question was for obtaining the state, as you have already been directed, or you are wanting to set the state, which I will throw out some additional direction below.

// ListBox method to select an item...
public void SetSelected(int index, bool value);
public ListBox.SelectedObjectCollection SelectedItems { get; } // to see all items selected...
// and, to capture when the selection is changing:
public event EventHandler SelectedIndexChanged;

// RadioButton method to get/set state:
public bool Checked { get; set; }
// and, to capture when the state has been changed:
public event EventHandler CheckedChanged;

// ComboBox methods to select item:
public override int SelectedIndex { get; set; }
public object SelectedItem { get; set; }
// and, to capture when the selection has changed:
public event EventHandler SelectedIndexChanged;

If you search on these, you should be able to find all the example code you need to see/understand how these are implemented in a form.

Cheers!

DdoubleD 315 Posting Shark

Sent you sent me a PM, I took a quick search: http://en.wikipedia.org/wiki/Law_of_cosines

I was then going to suggest that ddanbe is your man for this question, but I see he is already on top of it.;)

DdoubleD 315 Posting Shark

Here you go....

private void DisplayResults()
    {
      textBoxCurrentPage.Text = curPage.ToString();
      int recStart = 0 + (RECORDS_PER_PAGE * (curPage - 1));
      int recEnd = recStart + RECORDS_PER_PAGE;
      listView1.BeginUpdate();
      listView1.Items.Clear();
      if (currentSearchResults != null)
      {
        for (int i1 = recStart; i1 < recEnd; i1++)
        {
          if (currentSearchResults.Length > i1)
          {
            ListViewItem lvi = listView1.Items.Add(currentSearchResults[i1].FormType.Name);
            lvi.SubItems.Add(currentSearchResults[i1].Caption);
            lvi.Tag = currentSearchResults[i1];
          }
          else
            break;
        }
          // reorder matching search item to be at top
          ReorderItemToTop(textBox1.Text);
      }
      listView1.EndUpdate();
      buttonNext.Enabled = (curPage < maxPage);
      buttonPrev.Enabled = (curPage > 1);
    }

    void ReorderItemToTop(string name)
    {
        // sort items so our FindItemWithText finds first closest match index...
        // this will put them in the best order based on ascending...
        // if there is an exact match to name, it will be found first in code below...
        listView1.Sort();

        // Locate item beginning with name's text...
        ListViewItem item = listView1.FindItemWithText(name, true, 0, true);

        // if found and more than one item, begin moving them up the list....
        // If an exact match was found, it will be put at the top...
        if (item != null && listView1.Items.Count > 1)
        {
            // begin moving matching items up...
            int index = 0; // this is the top where we will put the first/best matching item
            do
            {
                // move item up to next top position...
                item.Remove();
                listView1.Items.Insert(index, item);

                // find next item beginning at index + 1 (skip one we just moved)...
                index++;
                item = listView1.FindItemWithText(name, true, index, true);

            } while (item != null); // until no more matches...
        }
    }
DdoubleD 315 Posting Shark

or perhaps this?:

public void MakeItemTopVisible(string name)
            {
                // Locate item beginning with name's text...
                ListViewItem item = listView1.FindItemWithText(name, false, 0, true);
                // make item first (top) item viewable in the list...
                listView1.TopItem = item;
            }
DdoubleD 315 Posting Shark

OK, is this what you want? Still not tested, but you can look at comments and logic to determine if I have understood your request:

void ReorderItemToTop(string name)
            {
                // sort items so our FindItemWithText finds first closest match index...
                // this will put them in the best order based on ascending...
                // if there is an exact match to name, it will be found first in code below...
                listView1.Sort();

                // Locate item beginning with name's text...
                ListViewItem item = listView1.FindItemWithText(name, false, 0, true);
                
                // if found and more than one item, begin moving them up the list....
                // If an exact match was found, it will be put at the top...
                if (item != null && listView1.Items.Count > 1)
                {
                    // begin moving matching items up...
                    int index = 0; // this is the top where we will put the first/best matching item
                    do
                    {
                        // move item up to next top position...
                        item.Remove();
                        listView1.Items.Insert(index, item);

                        // find next item beginning at index + 1 (skip one we just moved)...
                        index++;
                        item = listView1.FindItemWithText(name, false, index, true);
                    
                    } while (item != null); // until no more matches...
                }
            }
DdoubleD 315 Posting Shark

Here's the thing I am trying to load an arraylist of objects with each object having several text properties. Now if I try to do this with this modified code below, I can see each element of the arraylist but not the properties belonging to each object P. I have read many books over the past few weeks and rewritten the code a lot, but I just can't make this work.

Any takers please.

if (Parts.Length > 0)
                Title = GetTitle(parentName);
            ArrayList ps = new ArrayList();
            for (int counter = 0; counter < Parts.Length - 2; counter++)
            {
                PersonalPhoto P = new PersonalPhoto();
               // PhotoStuff P = new PhotoStuff();
                P.FileName = Parts[counter];
                P.DateTaken = GetDatePictureTaken(temp);
                P.Title = Title[counter];
                ps.Add(P);
            }

To access the items in your ArrayList ps, you need to cast the item back to type PersonalPhoto:

for (int i=0; i<ps.Count; i++)
{
  PersonalPhoto p = (PersonalPhoto)ps[i];
  // Now you can access the PersonalPhoto item's properties (eg. p.FileName)
  Console.WriteLine(p.FileName);
}

As an alternative, you could use a strong-typed List instead of an ArrayList:

List<PersonalPhoto> ps = new List<PersonalPhoto>();

            for (int counter = 0; counter < Parts.Length - 2; counter++)
            {
                PersonalPhoto P = new PersonalPhoto();
                // PhotoStuff P = new PhotoStuff();
                P.FileName = Parts[counter];
                P.DateTaken = GetDatePictureTaken(temp);
                P.Title = Title[counter];
                ps.Add(P);
            }

            // access each List/array element as PersonalPhoto...
            foreach (PersonalPhoto p in ps)
            {
                Console.WriteLine(p.FileName);
                Console.WriteLine(p.Title);
                // .... etc.
            }
            // or using index like:
            for (int i = 0; i < ps.Count; i++)
            {
                Console.WriteLine(ps[i].FileName); …
valter commented: Very helpful, solved for what was for me a difficult problem +3
DdoubleD 315 Posting Shark

Please see this and mark as solved if it answers your question: .NET Remoting Examples...

DdoubleD 315 Posting Shark

Quite a few people have been asking how they can get their applications to talk to each other. More specifically, they have been wanting to know how to access information from another running application using .NET Remoting.

Not having done this before, I decided to take up the challenge and create a simple example of this approach. Thus, this code snippet and attached solution. I only posted relevant code in the snippet, but all projects and files can be found in the attached solution.

The SimpleServer form application runs a form having a textbox that I added some default text to, but you can change this value as you are testing the implementation of the Client form applications.

The SimpleClient1 and SimpleClient2 form applications run a form having a multiline textbox and a button to retrieve text from the SimpleServer application.

In both the SimpleServer and SimpleClient1 examples, the application loads the RemoteConfiguration settings from a configuration file. This is probably the best way to go, as it allows these settings to be modified (to change port, etc.) without the need to recompile the applications

The SimpleServer2 example has the RemoteConfiguration settings hardcoded, and demonstrates using TcpClientChannel as well as Activator.GetObject to communicate with the SimpleServer application.

Cheers!

EDIT: Note that I don't have more than one machine, so I could only perform local machine tests. If you try this on two machines, you will need (at a minimum) to adjust the SimpleServer.config …

ddanbe commented: Great! +4
DdoubleD 315 Posting Shark

Add a KeyDown event:

private void textBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (Control.ModifierKeys == Keys.Space)
                ;//spacebar was pressed
        }

Sorry, I just realized I compared apples to oranges somewhat.... Try this instead:

private void textBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Space)
                ;//spacebar was pressed
        }

or, you can also do it this way:

private void textBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == ' ')
                ;//spacebar was pressed
        }
DdoubleD 315 Posting Shark

Ya well , it can works for all keys, i just want for space key.....

Add a KeyDown event:

private void textBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (Control.ModifierKeys == Keys.Space)
                ;//spacebar was pressed
        }
DdoubleD 315 Posting Shark

1) Yes on the Clear() method...
2) I wouldn't add this student to the Students list until they press the OK button; what if they press Cancel?
3) You really don't need to add the student's name to anything until they press the OK button: testscores.name = nameTbox.Text . You need to do that before you add testscores to your Students list though...

DdoubleD 315 Posting Shark

Sure. Here is the information I need:
1) Explanation of what the newstudent form is supposed to do; I know you are using multi-forms for this project, so specifically what the "newstudent" form's purpose is...
2) post the code from the newstudent.designer.cs file

DdoubleD 315 Posting Shark

Ah gotcha, and one last real quick one before I dive into the insanity of my programming ways lol, when your saying class myOtherForm : Form the myOtherForm = the name of the other form(s) I want to be able to access that class.cs and Form = the class name (I.E. student).

I'm sorry if I sound dumb with this, I just like to make sure my details are clearly put before I dive into it head first and then cause a bunch of issue and look even stupider, thanks.

Exactly! Here is an example....

// STUDENT CLASS
    public class student
    {
        // storage/getter/setter property...
        public string Name { get; set; }

        public List<int> Scores = new List<int>();
        

        /* ...
         * your other code here I left out for brevity...
         * ...
         * */

        // average all test scores for class/school or whatever is in our list...
        public static int averageAllStudents(List<student> Students)
        {
            int totScores = 0; // operand is total of all scores for all students
            int totCount = 0;  // dividend is total count of all score entries for all students

            // for every student
            foreach (student s in Students)
            {
                // and for every student score
                foreach (int score in s.Scores)
                {
                    totScores += score; // add score
                    totCount++; // increment count
                }
            }
            return totScores / totCount; // return average
        }

        // completely optional...,but to demonstrate how to override ToString to return name
        public override string ToString()
        {
            return this.Name;
        }
    }

Then, …

ddanbe commented: Who said I was tenacious?? Great! :) +14
DdoubleD 315 Posting Shark

Here is an example of how you could build a dynamic table to hold your data. The field names and data types are up to you to decide, etc.:

public void BuildDynamicTableArrayExample()
        {
            DataTable dt = new DataTable(); // table to hold each record
            dt.Columns.Add(new DataColumn("FieldName1", typeof(string))); // Create a string column dynamically
            dt.Columns.Add(new DataColumn("FieldName2", typeof(int))); // create an int column dyn
            dt.Columns.Add(new DataColumn("FieldName3", typeof(double))); // create a double column dyn
            for (int r = 0; r < 10; r++) // generate 10 rows of data
            {
                DataRow dr = dt.NewRow();   // create a row object of table's type defined above

                dr["FieldName1"] = "data " + r; // add some data...
                dr["FieldName2"] = r;
                dr["FieldName3"] = (double)r;

                dt.Rows.Add(dr); // add the row to the table
            }
        }
DeOiD commented: very good example +3
DdoubleD 315 Posting Shark

I cannot tell from the code statements why you are getting the error. I suggest you zip up the project and attach.

serkan sendur commented: i agree +10
DdoubleD 315 Posting Shark

excuse me ?

This code allows you to pass the URL of the file you want to download from the web, along with a local path where to save the file, then will call a messagebox when completed, but you can do a shutdown when that event is called instead of MessageBox:

public static void Test()
        {
            DownloadFile dlf = new DownloadFile();
            //string url = @"http://www.daniweb.com/alphaimages/misc/logo/logo.gif";
            string url = @"http://upload.wikimedia.org/wikipedia/commons/thumb/7/75/Wikimedia_Community_Logo.svg/30px-Wikimedia_Community_Logo.svg.png";
            dlf.Download(url, @"c:\temp");
        }
        void Download(string url, string targetDir)
        {

            // Create an instance of WebClient
            WebClient client = new WebClient();

            // Hookup DownloadFileCompleted Event
            client.DownloadFileCompleted +=
                new AsyncCompletedEventHandler(client_DownloadFileCompleted);

            Uri uri = new Uri(url);
            string fileName = System.IO.Path.GetFileName(uri.LocalPath);
            string destFile = System.IO.Path.Combine(targetDir, fileName);

            try
            {
                // Start the download and copy the file to c:\temp
                client.DownloadFileAsync(uri, destFile);
            }
            catch (WebException e)
            {
                MessageBox.Show(e.Message);
            }
            catch (InvalidOperationException e)
            {
                MessageBox.Show(e.Message);
            }
        }

        void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            MessageBox.Show("File downloaded. OK to shutdown now...");
        }
sknake commented: Thats neat. I don't think i will mention how I have been downloading files :P +15
DdoubleD 315 Posting Shark

That MSI Analyzer is pretty cool, but here is a simplified answer I whipped up for ya:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices; // Deploying a .NET component customization
using WindowsInstaller;
using System.IO;
using System.Collections;

namespace MSIDataBaseStuff
{
    public partial class Form1 : Form
    {
        [System.Runtime.InteropServices.ComImport(),
            System.Runtime.InteropServices.Guid
            ("000C1090-0000-0000-C000-000000000046")]
        class Installer { }

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            FileInfo msiFile = new FileInfo("setup1.msi");

            // open MSI database
            WindowsInstaller.Installer inst = (WindowsInstaller.Installer)new Installer();
            Database instDb = inst.OpenDatabase(msiFile.FullName,
                WindowsInstaller.MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);

            // query the database
            WindowsInstaller.View view = instDb.OpenView
                ("Select `Property`,`Value` FROM `Property`");
            view.Execute(null);

            //fetch each record...
            Record record = view.Fetch();
            while (record != null)
            {
                int iRow = dataGridView1.Rows.Add();
                dataGridView1.Rows[iRow].Cells[0].Value = record.get_StringData(1);// property
                dataGridView1.Rows[iRow].Cells[1].Value = record.get_StringData(2);// value

                record = view.Fetch();
            }

            // close the database
            view.Close();
        }
    }
}
partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.dataGridView1 = new System.Windows.Forms.DataGridView();
            this.Property = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Value = new System.Windows.Forms.DataGridViewTextBoxColumn();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
            this.SuspendLayout(); …
serkan sendur commented: havent checked yet but if works, oh man! +9
DdoubleD 315 Posting Shark

Following from http://www.albahari.com/nutshell/ch24.aspx

Extracting “name = value” pairs (one per line):

string r = @"(?m)^\s*(?'name'\w+)\s*=\s*(?'value'.*)\s*(?=\r?$)";

string text =
  @"id = 3
    secure = true
    timeout = 30";

foreach (Match m in Regex.Matches (text, r))
  Console.WriteLine (m.Groups["name"] + " is " + m.Groups["value"]);

id is 3
secure is true
timeout is 30

ddanbe commented: What can you do if you are not busy? +13
DdoubleD 315 Posting Shark

I don't see any difference except I crammed it all in one header file. I am using VS2008 compiler. Here is the header code I have:

#ifndef POINT3D_H
#define POINT3D_H
 
#ifndef POINT_H
#define POINT_H
 
#include <iostream>
 
template <typename T>
class Point
{
protected:
	T X,Y,Z;
public:
 
	Point(const T x, const T y, const T z) : X(x), Y(y), Z(z) {}
 
	T getX() {return X;};
	T getY() {return Y;};
	T getZ() {return Z;};
 
	void Output();
 
};
 
template< typename T>
void Point<T>::Output()
{ 
	std::cout << "x: " << X << " y: " << Y << " z: " << Z << std::endl;
}
 
#endif
//////////////////////

//////////////////////
template <typename T>
class Point3D : public Point<T>
{
	//T X,Y,Z;
	public:
		Point3D(const T x, const T y, const T z) : Point<T>(x,y,z) {}
 
		void Output3D();
};
 
template< typename T>
void Point3D<T>::Output3D()
{
	std::cout << "3D" << std::endl;
 
	//these both show junk values
	std::cout << "X: " << this->X << std::endl;
	std::cout << "X: " << X << std::endl;
 
	//this says "there are no arguments to 'getX' that depend on a template parameter, so a declaration of 'getX' must be available
	double x = getX();
	std::cout << "X: " << x << std::endl;
}
 
#endif
daviddoria commented: thanks for the response! +5
DdoubleD 315 Posting Shark

You need to size your cannon_ball array before using it:

cannon_ball = new GameObject[max_cannon_balls];
Ramy Mahrous commented: Good +10
DdoubleD 315 Posting Shark
string[] ar = listBox1.SelectedItems.Cast<string>().ToArray<string>();

Wanted to +rep you, but I guess I already did somewhere and it wouldn't let me. Anyway, that is a very clean line of code I haven't seen before--kudos! I hope I remember it the next time I do that.;)

serkan sendur commented: chic +8
kvprajapati commented: Thanks! +15
DdoubleD 315 Posting Shark

Here is another way to do it:

Image img = Image.FromFile(fileName);
            Bitmap bmpInverted = new Bitmap(img.Width, img.Height);
            ImageAttributes ia = new ImageAttributes();
            ColorMatrix cmPicture = new ColorMatrix(new float[][]
            {
                new float[] {-1, 0, 0, 0, 0},
                new float[] {0, -1, 0, 0, 0},
                new float[] {0, 0, -1, 0, 0},
                new float[] {0, 0, 0, 1, 0},
                new float[] {1, 1, 1, 0, 1}
            });
            ia.SetColorMatrix(cmPicture);//cm);
            Graphics g = Graphics.FromImage(bmpInverted);
            g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
            g.Dispose();
            img.Dispose();

            // use the bmpInverted object, which contains the inverted bitmap
            pictureBox1.Image = bmpInverted;

I don't know how the speed compares to sknake's example, but he probably would know.;)

sknake commented: another good way to go about it +14
DdoubleD 315 Posting Shark

Sure, if that is what you really want to do:

public Form2(Control [] controls) {}
//or
    public Form2(Button btn1, Button btn2, Button btn3)// etc.
    {}

or, you could even pass in reference to other form if the called form will know the controls and they are accessible:

public Form2(Form form1) {}
Diamonddrake commented: That's how I would have done it! +3
ddanbe commented: Passing a Form to a Form, nice! +12
DdoubleD 315 Posting Shark

please give me some c# code sample even pseudocode.

Those are options for launching a separate appwiz process with the selected option. To launch the process:

Process appwiz = new Process();

            appwiz.StartInfo.FileName = "control";
            appwiz.StartInfo.Arguments = "appwiz.cpl,,0";// change or remove program option

            appwiz.Start();
serkan sendur commented: chic +8
DdoubleD 315 Posting Shark

This thread seems to have been answered in another thread: http://www.daniweb.com/forums/thread31105.html

sknake commented: Thanks! +13
DdoubleD 315 Posting Shark
private void SetCurrentValuesForParameterField(ParameterFields parameterFields)
        {
            ParameterValues currentParameterValues = new ParameterValues();
            foreach (string str in td.Values)
            {
                ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
                parameterDiscreteValue.Value = str;
                currentParameterValues.Add(parameterDiscreteValue);
            }
         ParameterField parameterField = parameterFields[PARAMETER_FIELD_NAME];------  here i get the exeption
            parameterField.CurrentValues = currentParameterValues;
        }

the code to bind reportviewer control:-

ParameterFields parameterFields = crystalReportViewer1.ParameterFieldInfo;
            SetCurrentValuesForParameterField(parameterFields);

Hi Wafaa. I looks like you added the param value, but did not add the new parameter to the field collection. See this MSDN example:

private ParameterFields AddParameter 
   (string paramName, string paramValue,
   ParameterFields paramFields)
{
   ParameterField paramField= new ParameterField ();
   ParameterDiscreteValue paramDiscreteValue = new 
   ParameterDiscreteValue ();
   ParameterValues paramValues = new ParameterValues ();

   // Set the name of the parameter to modify.
   paramField.ParameterFieldName = paramName;

   // Set a value to the parameter.
   paramDiscreteValue.Value = paramValue;
   paramValues.Add (paramDiscreteValue);
   paramField.CurrentValues = paramValues;

   // Add the parameter to the ParameterFields collection.
   paramFields.Add (paramField);
   return paramFields;
}
DdoubleD 315 Posting Shark

You forgot to include the contents of: "nodeType.h"

kyosuke0 commented: very helpful +1
DdoubleD 315 Posting Shark

Hi. Did you figure this problem out yet? I could simply give you a short and precise answer to your question--Yes (LOL), but you probably want to know what the reason is too, right?

Can you attach the report file and list what the "3 specific values" are?

DdoubleD 315 Posting Shark

I noticed this link posted by adatapost, which seems to use the dashed outline on the drag you are looking to replicate, but cannot be sure because I did not get to see your IMG tag. Anyway, it's a TreeView drag/drop I believe, but the owner drawn stuff is probably the same with some minor tweaks: http://www.codeproject.com/KB/tree/mwcontrols.aspx?msg=904987

Cheers!

serkan sendur commented: chic +7
DdoubleD 315 Posting Shark

The IDE creates a copy of the file in your "Text files" folder you added to the project. The "Copy to output directory" option says to copy a version of that one to the bin folder where the app.exe is placed. So, you shouldn't need to specify a path with the filename.

When you run your exe, the StreamReader should look for it in that folder if you omit the path from the filename. In other words, it will find the file in the current working directory. So, if you are running the exe from a different directory, it will NOT find it.

DdoubleD 315 Posting Shark

Welcome to C#! As far as I can tell so far, you need help understanding what your assignment is, and you are not ready to begin coding it in C# until you do understand that. I think you should contact professor or classmate to get a better understanding of the actual assignment first, begin coding what you can in C#, then begin asking C# questions if you need too.

ddanbe commented: Nice response! +8
serkan sendur commented: chic +7
DdoubleD 315 Posting Shark

Just FYI:

I believe this practice was carried over as the C# language was developed. In C/CPP, I got into the habit of putting in the comma after the last definition for a few reasons:

1) easier editing when you want to append to list of enums
2) easier editing when you want to reorder with cut and paste
3) easier editing when you want to search and replace, such as wanting to append characters to the end of selected items you would just replace the "," with "_FLD," or "_SIZ", etc.

In addition, we would often place a final definition to indicate the total definitions (eg. TOTFIELDS). This last entry was very useful for loops and allocations. Not so much now as C# makes life so much easier, but I still do this. However, in this particular case, you would definitely want to leave off the trailing comma because you would never want to append a definition past the TOTFIELDS.

ddanbe commented: Thanks for the extra clarification! +8
sknake commented: interesting +8
DdoubleD 315 Posting Shark

OK. Instead of initializing "date" outside the loop, restore it inside the loop, but use the Convert.ToDateTime. This is the value from each record we want to compare to to see if it is a min or max value.

Instead of initializing Start and EndDate inside the loop, move those outside the loop (where you have "date" currently): set your StartDate to a very high value; and your EndDate to a very low value.

This should fix it--let me know.

ddanbe commented: Good explanation. +8
DdoubleD 315 Posting Shark

If your date strings are formatted correctly for string comparisons, you can just initialize them and do a comparison for min and max for each row in your loop (pseudocode):

if minDate = "" or minDate > date then
    minDate = date;
if maxDate = "" or maxDate < date then
    maxDate = date;
arelius commented: He was execellent at helping me out and solving the probelm I had. Very reliable as well. +1
DdoubleD 315 Posting Shark

Check out these ListView methods:

public ListView.SelectedListViewItemCollection SelectedItems { get; }
//or
        public ListView.SelectedIndexCollection SelectedIndices { get; }

//with
        public bool ListViewItem.Checked { get; set; }
DdoubleD 315 Posting Shark

Here is the modification:

public Main()
        {
            InitializeComponent();

            //String admin = "Admin"; // not being used?
            this.Load += new System.EventHandler(this.Main_Load);
        }
        private void Main_Load(object sender, EventArgs e)
        {
            if ("Admin" == user)

                btnAdmin.Enabled = true;

            else

                btnAdmin.Enabled = false;
        }
Rhuntsman21 commented: Thanks for the help. +1
DdoubleD 315 Posting Shark

QUESTIONS:
1) Where/when are you executing this code?
2) Where/how are you setting the value of the string "user"?
3) Can you include the whole code text?

kvprajapati commented: Good questions. +10