0

I want to change the following program into one that takes a list of doubles from a data base (rounded to two decimal places and in ascending order) and displays them in a datagrid. My current program sort of infinitely scrolls up and down, but it's skin-deep, since the numbers are immediately forgotten. I want my program to be able to display all the numbers from the database in a scrollable table and I want the datagrid to remember them.

Only problem is I have no experience with databases whatsoever. I don't know how to connect to them, how to import them, or anything like that. Could someone help me get started with this? I at least need to have access to the database (and which one), I suppose I can figure out how to format it on my own.

Also, important question for me: Are databases accessed from online or can they be downloaded and accessed locally.

Thanks

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Xml.Serialization;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SterlingDataGrid
{

public partial class Form1 : System.Windows.Forms.Form
{

   // private SterlingLib.STIQuote stiQuote = new SterlingLib.STIQuote();
    //private SterlingLib.STIApp stiApp = new SterlingLib.STIApp();
    //private List<string> listMsg = new List<string>();
   // private bool bModeXML = true;

    private Panel buttonPanel = new Panel();
    private Panel buttonPanel2 = new Panel();

    private DataGridView sterlingDataGridView = new DataGridView();
    private Button upButton = new Button();
    private Button downButton = new Button();
    private TextBox quoteBox = new TextBox();

    public static double num1 = 1203.5;


    public Form1()
    {
        this.Load += new EventHandler(Form1_Load);

    }

    private void Form1_Load(System.Object sender, System.EventArgs e)
    {
        SetupLayout();
        SetupDataGridView();
        PopulateDataGridView();
    }

    private void upButton_Click(object sender, EventArgs e)
    {
        num1 += .1;
        sterlingDataGridView.Rows[1].Cells[2].Value = num1;
        for (int r = 2; r < 10; r++)
        {
            sterlingDataGridView.Rows[r].Cells[2].Value = (double)(sterlingDataGridView.Rows[r - 1].Cells[2].Value) - 0.1;
        }
    }

    private void downButton_Click(object sender, EventArgs e)
    {
        num1 -= .1;
        sterlingDataGridView.Rows[1].Cells[2].Value = num1;
        for (int r = 2; r < 10; r++)
        {
            sterlingDataGridView.Rows[r].Cells[2].Value = (double)(sterlingDataGridView.Rows[r - 1].Cells[2].Value) - 0.1;
        }
    }

    //***NEW***
    private void sterlingDataGridView_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            DataGridView.HitTestInfo hit = sterlingDataGridView.HitTest(e.X, e.Y);
            if (hit.Type == DataGridViewHitTestType.Cell)
            {

                //clickedCell = sterlingDataGridView.Rows[hit.RowIndex].Cells[hit.ColumnIndex];
                if(hit.ColumnX == 0)

                MessageBox.Show("TEST COMPLETE. ROW INDEX: " + hit.RowIndex + " COLUMN INDEX: " + hit.ColumnIndex);
            }
        }
    }

    private void SetupLayout()
    {
        this.Size = new Size(600, 500);

        sterlingDataGridView.AutoSize = true;

        upButton.Text = "^";
        upButton.Location = new Point(10, 10);
        upButton.Click += new EventHandler(upButton_Click);


        downButton.Text = "v";
        downButton.Location = new Point(100, 10);
        downButton.Click += new EventHandler(downButton_Click);

        sterlingDataGridView.MouseDown += new MouseEventHandler(sterlingDataGridView_MouseDown);


        buttonPanel.Controls.Add(upButton);
        buttonPanel.Controls.Add(downButton);
        buttonPanel.Controls.Add(quoteBox);

        quoteBox.Location = new Point(100, 0 + (upButton.Height*2));
        downButton.Location = new Point(110, 0 + upButton.Height);
        upButton.Location = new Point(110, 0);

        buttonPanel.Height = 197;
        buttonPanel.Dock = DockStyle.Bottom;

        buttonPanel2.Width = 231;
        buttonPanel2.Dock = DockStyle.Right;

     //   buttonPanel.Controls.
        this.Controls.Add(this.buttonPanel);
        this.Controls.Add(this.buttonPanel2);
    }

    private void SetupDataGridView()
    {
        this.Controls.Add(sterlingDataGridView);

        sterlingDataGridView.ColumnCount = 6;

        sterlingDataGridView.ColumnHeadersDefaultCellStyle.BackColor = Color.Navy;
        sterlingDataGridView.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
        sterlingDataGridView.ColumnHeadersDefaultCellStyle.Font =
            new Font(sterlingDataGridView.Font, FontStyle.Bold);

        sterlingDataGridView.Name = "sterlingDataGridView";
        sterlingDataGridView.Location = new Point(8, 8);
        sterlingDataGridView.Size = new Size(500, 250);
        sterlingDataGridView.AutoSizeRowsMode =
            DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
        sterlingDataGridView.ColumnHeadersBorderStyle =
            DataGridViewHeaderBorderStyle.Single;
        sterlingDataGridView.CellBorderStyle = DataGridViewCellBorderStyle.Single;
        sterlingDataGridView.GridColor = Color.Black;
        sterlingDataGridView.RowHeadersVisible = false;
        sterlingDataGridView.ReadOnly = true; //***NEW***


        sterlingDataGridView.Columns[0].Width = sterlingDataGridView.Columns[2].Width / 2;
        sterlingDataGridView.Columns[1].Width = sterlingDataGridView.Columns[2].Width/2;
        sterlingDataGridView.Columns[3].Width = sterlingDataGridView.Columns[2].Width / 2;
        sterlingDataGridView.Columns[4].Width = sterlingDataGridView.Columns[2].Width / 2;
        sterlingDataGridView.Columns[5].Width = sterlingDataGridView.Columns[2].Width / 2;

        sterlingDataGridView.Columns[0].Name = "Bid";
        sterlingDataGridView.Columns[1].Name = "BidQty";
        sterlingDataGridView.Columns[2].Name = "";
        sterlingDataGridView.Columns[3].Name = "AskQty";
        sterlingDataGridView.Columns[4].Name = "Ask";
        sterlingDataGridView.Columns[5].Name = "Vol";

        sterlingDataGridView.SelectionMode =
            DataGridViewSelectionMode.FullRowSelect;
        sterlingDataGridView.MultiSelect = false;
        sterlingDataGridView.Dock = DockStyle.Fill;


    }

    void PopulateDataGridView()
    {

        double num2 = num1 - .1;
        double num3 = num2 - .1;
        double num4 = num3 - .1;
        double num5 = num4 - .1;
        double num6 = num5 - .1;
        double num7 = num6 - .1;
        double num8 = num7 - .1;
        double num9 = num8 - .1;
        string[] row0 = { "", "", "      ^", "", "", "" };
        string[] row1 = { "", "", System.Convert.ToString(num1), "", "", "" };
        string[] row2 = { "", "", System.Convert.ToString(num2), "", "", "" };
        string[] row3 = { "", "", System.Convert.ToString(num3), "", "", "" };
        string[] row4 = { "", "", System.Convert.ToString(num4), "", "", "" };
        string[] row5 = { "", "", System.Convert.ToString(num5), "", "", "" };
        string[] row6 = { "", "", System.Convert.ToString(num6), "", "", "" };
        string[] row7 = { "", "", System.Convert.ToString(num7), "", "", "" };
        string[] row8 = { "", "", System.Convert.ToString(num8), "", "", "" };
        string[] row9 = { "", "", System.Convert.ToString(num9), "", "", "" };
        string[] row10 = { "", "", "      v", "", "", "" };


        sterlingDataGridView.Rows.Add(row0);
        sterlingDataGridView.Rows.Add(row1);
        sterlingDataGridView.Rows.Add(row2);
        sterlingDataGridView.Rows.Add(row3);
        sterlingDataGridView.Rows.Add(row4);
        sterlingDataGridView.Rows.Add(row5);
        sterlingDataGridView.Rows.Add(row6);
        sterlingDataGridView.Rows.Add(row7);
        sterlingDataGridView.Rows.Add(row8);
        sterlingDataGridView.Rows.Add(row9);
        sterlingDataGridView.Rows.Add(row10);



        sterlingDataGridView.Columns[0].DisplayIndex = 0;
        sterlingDataGridView.Columns[1].DisplayIndex = 1;
        sterlingDataGridView.Columns[2].DisplayIndex = 2;
        sterlingDataGridView.Columns[3].DisplayIndex = 3;
        sterlingDataGridView.Columns[4].DisplayIndex = 4;
    }




}      
}
jdewitte
  • 135
  • 3
  • 13

1 Answers1

0

I would recommend following link for a good start over LINQ to SQL:

fastest-start-for-linq-to-sql

using-linq-to-sql-tutorials

Good luck!

Since you are going to have an application which is supposed to be downloaded and run,i suggest using XML or TEXT file as a local database,which can be a simple file beside your application and doesn't need installation.here's a good start for working XML:

LINQ to XML Tutorial

you can also search for "LINQ to XML"+beginning or tutorial for some useful articles about LINQ to XML.

IT Seeker
  • 82
  • 8
  • about your last question,Databases are usually "server"s,meaning they serve you for the data you need to keep and retrieve,according to your need,you can decide whether to have a online database or just a local database that can be even a simple XML or TEXT file. – IT Seeker Dec 18 '12 at 18:48
  • Ok, well ideally, the finished program would be something the user could download and run on their own. Am I going to be have to have them download and set up the database as well? Because that might be a dealbreaker for me. If that's the case I may just make a really large array or a binary search tree (if I can figure out how to do it in C#). – jdewitte Dec 19 '12 at 00:06