Click here to Skip to main content
15,895,709 members
Home / Discussions / C#
   

C#

 
AnswerRe: Typical applications design and development code samples Pin
Dalek Dave12-Jan-11 5:47
professionalDalek Dave12-Jan-11 5:47 
GeneralRe: Typical applications design and development code samples Pin
fjdiewornncalwe12-Jan-11 8:10
professionalfjdiewornncalwe12-Jan-11 8:10 
QuestionMessage Removed Pin
12-Jan-11 2:33
LAPEC12-Jan-11 2:33 
AnswerRe: C#: How to retrieve text from dgView cell and displayit in the button? PinPopular
Dave Kreskowiak12-Jan-11 2:49
mveDave Kreskowiak12-Jan-11 2:49 
AnswerRe: C#: How to retrieve text from dgView cell and displayit in the button? Pin
Enobong Adahada12-Jan-11 2:57
Enobong Adahada12-Jan-11 2:57 
GeneralRe: C#: How to retrieve text from dgView cell and displayit in the button? Pin
LAPEC12-Jan-11 3:15
LAPEC12-Jan-11 3:15 
GeneralRe: C#: How to retrieve text from dgView cell and displayit in the button? Pin
Enobong Adahada12-Jan-11 3:21
Enobong Adahada12-Jan-11 3:21 
GeneralRe: C#: How to retrieve text from dgView cell and displayit in the button? Pin
LAPEC12-Jan-11 3:43
LAPEC12-Jan-11 3:43 
Here is the code...

I have two forms on my project (Form1 & Form2).

-In Form1 I have two Buttons (Starter & Main). Both these buttons on click event, they call database sql-query and genereate into form the records as Buttons.
-In Form2 I have a Button (Starter) and DataGridView. Also this button on click event calls database sql-query and generates records in DatagridView. DataGridView has four columns:

(Note: On columns [0] and [1] data are genereated from database, the columns [2] and [3] are template columns genereated at run-time also filled with data at run-time)

Now in Form2 when I double_click inside the Cell under the Qty In Stock column, a dialog-box pops up and allows me to enter the number in to that particular cell. Lets say Row-1: like so...

FoodName     FoodType     Qty In Stock     Status
-----------------------------------------------------------
Soup         Starter      10               Allways On Stock


Based on this: How can I take the value of that cell = 10 and dispalyit on the bottom-right corner of the Button (in this case button Soup). This is what the Soup Button should look like (in Form1): (Note: The Button called Soup is generated from database...)

##############
#   Soup     #
#         10 #
##############


Here is the code of dataGridView1_CellClick event (in Form2)...

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 2)
            {
                // Value is given in case the cell is empty
                string cellContent = "0";
                if (this.dataGridView1[e.ColumnIndex, e.RowIndex].Value != null)
                {
                    cellContent = this.dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
                }
                
                using (InputBox ib = new InputBox("Enter new stock amount:", this.dataGridView1[0, e.RowIndex].Value.ToString(), cellContent))
                {
                    if (ib.ShowDialog() == DialogResult.OK)
                    {
                        this.dataGridView1[e.ColumnIndex, e.RowIndex].Value = ib.Result;
                        cellContent = ib.Result;
                    }
                }
            }
        }


This is the code of InputBox dialog where it allows me to enter quantity in to the Cell of dataGridView1...

public partial class InputBox : Form
    {
        public InputBox(string text, string caption, string defaultValue)
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            this.Text = caption;  //.Clone().ToString();


            Size size;
            using (Graphics g = this.CreateGraphics())
            {
                Rectangle screen = Screen.PrimaryScreen.WorkingArea;
                SizeF sizeF = g.MeasureString(text, lblPrompt.Font, screen.Width - 20);
                size = sizeF.ToSize();
                size.Width += 4;
            }

            if (size.Width < 310)
            {
                size.Width = 310;
            }
            Size clientSize = this.ClientSize;
            clientSize.Width += size.Width - lblPrompt.Width;
            clientSize.Height += size.Height - lblPrompt.Height;
            this.ClientSize = clientSize;
            lblPrompt.Text = text;
            txtResult.Text = defaultValue;
            this.DialogResult = DialogResult.Cancel;
        }

        void CancelButtonClick(object sender, System.EventArgs e)
        {
            result = null;
            this.Close();
        }

        void AcceptButtonClick(object sender, System.EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            result = txtResult.Text;
            this.Close();
        }

        string result;

        public string Result
        {
            get
            {
                return result;
            }
        }

        private void btnSeven_Click(object sender, EventArgs e)
        {
            txtResult.Text += btnSeven.Text + "7";
        }

        private void btnTwo_Click(object sender, EventArgs e)
        {
            txtResult.Text += btnTwo.Text + "2";
        }

        private void btnOne_Click(object sender, EventArgs e)
        {
            txtResult.Text += btnOne.Text + "1";
        }

        private void btnSix_Click(object sender, EventArgs e)
        {
            txtResult.Text += btnSix.Text + "6";
        }

        private void btnFive_Click(object sender, EventArgs e)
        {
            txtResult.Text += btnFive.Text + "5";
        }

        private void btnFour_Click(object sender, EventArgs e)
        {
            txtResult.Text += btnFour.Text + "4";
        }

        private void btnNine_Click(object sender, EventArgs e)
        {
            txtResult.Text += btnNine.Text + "9";
        }

        private void btnEight_Click(object sender, EventArgs e)
        {
            txtResult.Text += btnEight.Text + "8";
        }

        private void btnThree_Click(object sender, EventArgs e)
        {
            txtResult.Text += btnThree.Text + "3";
        }

        private void btnZero_Click(object sender, EventArgs e)
        {
            txtResult.Text += btnZero.Text + "0";
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            txtResult.Clear();
            txtResult.Focus();
        }
    }


This is the code how to create Buttons on Form1, and then take the database records and asign values to these buttons...

private void FoodAddButtons(DataTable table)
        {
            int xpos = 5;
            int ypos = 5;
            int space = 2;
            VistaButtonTest.VistaButton newButton = null;
            DtposMenuBS.Sort = "FoodPrice";
            try
            {
                foreach (DataRowView dr in DtposMenuBS.List)
                {
                    newButton = new VistaButtonTest.VistaButton();
                    newButton.ButtonText = dr["FoodName"].ToString();
                    newButton.AutoEllipsis = true;
                    newButton.Width = 152;
                    newButton.Height = 70;
                    newButton.CornerRadius = 4;
                    newButton.Font = new System.Drawing.Font("Arial Narrow", 15.00F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    newButton.BaseColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
                    newButton.ForeColor = System.Drawing.Color.Black;
                    newButton.HighlightColor = System.Drawing.Color.DarkGray;
                    newButton.GlowColor = System.Drawing.Color.DimGray;
                    if (xpos + newButton.Width > this.FoodMenuPanel.ClientSize.Width)
                    {
                        ypos += newButton.Height + space;
                        xpos = 5;
                    }
                    newButton.Location = new Point(xpos, ypos);
                    xpos += newButton.Width + space;
                    newButton.Click += ItemSelection1;
                    this.FoodMenuPanel.Controls.Add(newButton);
                }
            }
            finally
            {
                DtposMenuBS.Sort = "";
            }
        }

GeneralRe: C#: How to retrieve text from dgView cell and displayit in the button? Pin
OriginalGriff12-Jan-11 4:55
mveOriginalGriff12-Jan-11 4:55 
AnswerRe: C#: How to retrieve text from dgView cell and displayit in the button? Pin
OriginalGriff12-Jan-11 3:03
mveOriginalGriff12-Jan-11 3:03 
AnswerRe: C#: How to retrieve text from dgView cell and displayit in the button? PinPopular
Eddy Vluggen12-Jan-11 3:07
professionalEddy Vluggen12-Jan-11 3:07 
QuestionDisable cd/dvd eject button with code Pin
Enobong Adahada12-Jan-11 0:18
Enobong Adahada12-Jan-11 0:18 
AnswerRe: Disable cd/dvd eject button with code Pin
Eddy Vluggen12-Jan-11 0:32
professionalEddy Vluggen12-Jan-11 0:32 
GeneralRe: Disable cd/dvd eject button with code Pin
Enobong Adahada12-Jan-11 0:38
Enobong Adahada12-Jan-11 0:38 
GeneralRe: Disable cd/dvd eject button with code Pin
Łukasz Nowakowski12-Jan-11 0:55
Łukasz Nowakowski12-Jan-11 0:55 
GeneralRe: Disable cd/dvd eject button with code Pin
Dalek Dave12-Jan-11 1:01
professionalDalek Dave12-Jan-11 1:01 
GeneralRe: Disable cd/dvd eject button with code Pin
Enobong Adahada12-Jan-11 1:05
Enobong Adahada12-Jan-11 1:05 
GeneralRe: Disable cd/dvd eject button with code Pin
Eddy Vluggen12-Jan-11 1:52
professionalEddy Vluggen12-Jan-11 1:52 
GeneralRe: Disable cd/dvd eject button with code Pin
Enobong Adahada12-Jan-11 2:41
Enobong Adahada12-Jan-11 2:41 
QuestionRe: Disable cd/dvd eject button with code Pin
Paladin200012-Jan-11 6:52
Paladin200012-Jan-11 6:52 
GeneralRe: Disable cd/dvd eject button with code Pin
GenJerDan12-Jan-11 4:08
GenJerDan12-Jan-11 4:08 
AnswerRe: Disable cd/dvd eject button with ---- (GpEdit.msc) Pin
Michael900017-Jan-11 8:55
Michael900017-Jan-11 8:55 
AnswerRe: Disable cd/dvd eject button with code Pin
Dalek Dave12-Jan-11 1:03
professionalDalek Dave12-Jan-11 1:03 
GeneralRe: Disable cd/dvd eject button with code Pin
Enobong Adahada12-Jan-11 1:07
Enobong Adahada12-Jan-11 1:07 
GeneralRe: Disable cd/dvd eject button with code Pin
Dalek Dave12-Jan-11 1:12
professionalDalek Dave12-Jan-11 1:12 

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.