Click here to Skip to main content
15,923,557 members
Home / Discussions / C#
   

C#

 
GeneralRe: Help with adding the NumericTextBox control Pin
Julius91126-Mar-09 4:04
Julius91126-Mar-09 4:04 
QuestionSending SMS from PPC 2003 emulator through a built-in GSM modem Pin
aarti1425-Mar-09 4:47
aarti1425-Mar-09 4:47 
AnswerRe: Sending SMS from PPC 2003 emulator through a built-in GSM modem Pin
Blue_Boy25-Mar-09 5:00
Blue_Boy25-Mar-09 5:00 
QuestionHelp needed with code, method of one class cannot access control on form? [modified] Pin
Lewis0125-Mar-09 4:41
Lewis0125-Mar-09 4:41 
AnswerRe: Help needed with code, method of one class cannot access control on form? Pin
Deresen25-Mar-09 4:54
Deresen25-Mar-09 4:54 
GeneralRe: Help needed with code, method of one class cannot access control on form? Pin
Lewis0125-Mar-09 5:01
Lewis0125-Mar-09 5:01 
AnswerRe: Help needed with code, method of one class cannot access control on form? Pin
Ian Shlasko25-Mar-09 5:09
Ian Shlasko25-Mar-09 5:09 
GeneralRe: Help needed with code, method of one class cannot access control on form? Pin
Lewis0125-Mar-09 5:26
Lewis0125-Mar-09 5:26 
Thanks. I'm beginning to understand. I think I've implemented the changes you suggested. However the orginal errors remain.

Here is the code that I now have:

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace keyFortress
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}


lView.cs

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlServerCe;
using System.Security.Cryptography;
using Microsoft.Win32;

namespace keyFortress
{
    class lView
    {
        public DataSet _DataSet;
        public SqlCeConnection _Conn;
        public SqlCeDataAdapter _DataAdapterTitles;

        public void GetData()
        {
            string strConn = @"Data Source = |DataDirectory|\psw01.sdf;Password=******";
            try
            {
                _Conn = new SqlCeConnection(strConn);

                // Fill DataSet
                string strSQL = "SELECT username, "
                    + "password "
                    + "FROM tbl_data "
                    + "ORDER BY username";

                _DataSet = new DataSet();
                _DataAdapterTitles = new SqlCeDataAdapter(strSQL, _Conn);
                _DataAdapterTitles.Fill(_DataSet, "tbl_data");

            }
            catch (Exception ex)
            {
                string msg = ex.Message.ToString();

                MessageBox.Show(msg, "Unable to retrieve data.",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }
        }

        // Load Data from the DataSet into the ListView
        public void LoadList(ListView myListView)
        {
            // Get the table from the data set
            DataTable dtable = _DataSet.Tables["tbl_data"];

            // Clear the ListView control
            listView1.Items.Clear();

            // Display items in the ListView control
            for (int i = 0; i < dtable.Rows.Count; i++)
            {
                DataRow drow = dtable.Rows[i];

                // Only row that have not been deleted
                if (drow.RowState != DataRowState.Deleted)
                {
                    // Define the list items
                    ListViewItem lvi = new ListViewItem(drow["username"].ToString());
                    lvi.SubItems.Add(drow["password"].ToString());

                    // Add the list items to the ListView
                    listView1.Items.Add(lvi);
                }
            }
        }
    }
}


Form1.cs

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;

namespace keyFortress
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            lView mylView = new lView();
            mylView.GetData();
            mylView.LoadList(listView1);
        }

        lView mylView = new lView();

    }
}


Form1.Designer.cs

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlServerCe;
using System.Security.Cryptography;
using Microsoft.Win32;

namespace keyFortress
{
    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.listView1 = new System.Windows.Forms.ListView();
            this.SuspendLayout();
            // 
            // listView1
            // 
            this.listView1.Location = new System.Drawing.Point(12, 28);
            this.listView1.Name = "listView1";
            this.listView1.Size = new System.Drawing.Size(131, 167);
            this.listView1.TabIndex = 0;
            this.listView1.UseCompatibleStateImageBehavior = false;
            this.listView1.View = View.Details;                         // Set the view to show details.
            this.listView1.LabelEdit = true;                            // Allow the user to edit item text.
            this.listView1.AllowColumnReorder = true;                   // Allow the user to rearrange columns.
            this.listView1.CheckBoxes = false;                          // Display check boxes.
            this.listView1.FullRowSelect = true;                        // Select the item and subitems when selection is made.
            this.listView1.MultiSelect = false;
            this.listView1.GridLines = false;                           // Display grid lines.
            
            // Attach Subitems to the ListView
            this.listView1.Columns.Add("username", -2, HorizontalAlignment.Left);
            this.listView1.Columns.Add("password", -2, HorizontalAlignment.Left);


            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 264);
            this.Controls.Add(this.listView1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.ListView listView1;
    }
}

GeneralRe: Help needed with code, method of one class cannot access control on form? Pin
Ian Shlasko25-Mar-09 5:41
Ian Shlasko25-Mar-09 5:41 
GeneralRe: Help needed with code, method of one class cannot access control on form? Pin
Lewis0125-Mar-09 5:56
Lewis0125-Mar-09 5:56 
GeneralRe: Help needed with code, method of one class cannot access control on form? Pin
Lewis0125-Mar-09 6:14
Lewis0125-Mar-09 6:14 
GeneralRe: Help needed with code, method of one class cannot access control on form? Pin
Ian Shlasko25-Mar-09 6:33
Ian Shlasko25-Mar-09 6:33 
QuestionPlease, I want program to solve numerical Analysis Equations ! Pin
Kh.Taheri25-Mar-09 4:35
Kh.Taheri25-Mar-09 4:35 
AnswerRe: Please, I want program to solve numerical Analysis Equations ! Pin
Deresen25-Mar-09 4:38
Deresen25-Mar-09 4:38 
GeneralRe: Please, I want program to solve numerical Analysis Equations ! Pin
Kh.Taheri4-Feb-17 14:08
Kh.Taheri4-Feb-17 14:08 
AnswerRe: Please, I want program to solve numerical Analysis Equations ! Pin
Tom Deketelaere25-Mar-09 4:40
professionalTom Deketelaere25-Mar-09 4:40 
GeneralRe: Please, I want program to solve numerical Analysis Equations ! Pin
Kh.Taheri4-Feb-17 14:08
Kh.Taheri4-Feb-17 14:08 
AnswerRe: Please, I want program to solve numerical Analysis Equations ! Pin
Le centriste25-Mar-09 4:41
Le centriste25-Mar-09 4:41 
GeneralRe: Please, I want program to solve numerical Analysis Equations ! Pin
Kh.Taheri4-Feb-17 14:07
Kh.Taheri4-Feb-17 14:07 
AnswerRe: Please, I want program to solve numerical Analysis Equations ! Pin
0x3c025-Mar-09 6:26
0x3c025-Mar-09 6:26 
GeneralRe: Please, I want program to solve numerical Analysis Equations ! Pin
Kh.Taheri4-Feb-17 14:06
Kh.Taheri4-Feb-17 14:06 
AnswerRe: Please, I want program to solve numerical Analysis Equations ! Pin
CPallini25-Mar-09 8:13
mveCPallini25-Mar-09 8:13 
GeneralRe: Please, I want program to solve numerical Analysis Equations ! Pin
Kh.Taheri4-Feb-17 14:03
Kh.Taheri4-Feb-17 14:03 
GeneralRe: Please, I want program to solve numerical Analysis Equations ! Pin
CPallini4-Feb-17 23:08
mveCPallini4-Feb-17 23:08 
AnswerRe: Please, I want program to solve numerical Analysis Equations ! Pin
Henry Minute25-Mar-09 11:36
Henry Minute25-Mar-09 11:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.