|
Hi Enobong Adahada
thanks for replying to my message, I have managed to work around my code refering to the question I posted yesterday
but for some reason its not getting the cell value number to display it in the button.
If you dont mind please you can have a look my question (under the View Unanswered Question) provided with sample of code
and tell me if I missing something....
Thanks in advance
kind regards
roni
|
|
|
|
|
Can you post the code u are using so i can
see if there are logic bugs.
|
|
|
|
|
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)
{
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)
{
InitializeComponent();
this.Text = caption;
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 = "";
}
}
|
|
|
|
|
Reason for my vote of 1: Why cut and paste that lot? Why did you not just give a link to your Q&A question? Now, you have two places with the same info, that potentially could duplicate work if anyone does answer.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
LAPEC wrote: no one seems to answer my question
There could be a number of reasons for that:
1) No body knew the answer.
2) No body could be bothered to work out what the question was, because of the large lump of code they didn't want to bother with.
3) You didn't seem to have shown much effort in working on your problem yourself.
4) Some combination of the above.
You have to remember: not everybody looks at Q&A; nobody here gets paid for this; most of us have jobs which do pay and expect a certain amount of work from us.
You aren't helping yourself by taking a whining, petulant tone in your "bump" message...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
LAPEC wrote: I thought that the Code Project Forum is there for people to help who dont have much knowledge on programming...
It's a forum, people meet. Sometimes they help each other, but being a member is no replacement for an education.
I are Troll
|
|
|
|
|
pls i want to disabled permanently my my cd/dvd eject buton.
thanks.
|
|
|
|
|
Enobong Adahada wrote: pls i want to disabled permanently my my cd/dvd eject buton.
Similar to this[^]?
That way you'd have an unusable drive that consumes power. How about disabling the entire drive?
I are Troll
|
|
|
|
|
I want to use code to open and close it, i don't want users to open it using the eject button.
|
|
|
|
|
And if your application hangs, user will have to restart the computer to open cd/dvd drive?
Don't forget to rate answer, that helped you. It will allow other people find their answers faster.
|
|
|
|
|
Or push a paper clip into the tiny hole!
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC League Table Link
CCC Link[ ^]
|
|
|
|
|
The users do not need to use the cd/dvd drives during a certain period in my office,
I want a code to disabled the Eject button to keep them out, at this this time.
is there a such a code in c#, i found some in vb.
Thank for you response.
|
|
|
|
|
Users either have access, or they don't. You're looking for a "Child Safety Lock" for your employees?
I are Troll
|
|
|
|
|
|
CD/DVD-Rom lockout? Why? What would prevent them from using a USB flash drive (or some other USB device) and using external files anyway? (I assume that is what you are trying to prevent.)
|
|
|
|
|
If you have the VB code, it should be fairly easy to translate...
...by someone who knows both VB and C#...
...me, not being one of those people.
|
|
|
|
|
Not a code example, but you can disable CDROM/Remoable Driver/etc. in Windows' Group Policy (at least in Windows 7)
|
|
|
|
|
Superglue.
Use a screwdriver to remove it.
Disconnect the wires.
As you see, lots of options available
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC League Table Link
CCC Link[ ^]
|
|
|
|
|
Thanks for the advice, but NO.
|
|
|
|
|
It's ok, I was only joking anyway!
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC League Table Link
CCC Link[ ^]
|
|
|
|
|
This One[^]
does not do exactly what you want, but hope will be much helpful in the way.
|
|
|
|
|
What about ejecting from Explorer?
|
|
|
|
|
This tip[^] I posted sometime ago disables it, but not permanently.
You could make the app run at start up (perhaps a service) so it is effectively permanently disabled.
|
|
|
|
|
I have small number of GUI attribute that i need to save in my application.
The attribute are simple ( windows size, window color, ext... ) and they need to be store in file ( can be XML or binary ).
I don't sure i know what is the fest and best way to write the code ?
Is it simple XML or serialization ?
Is there some example ?
Thanks.
|
|
|
|
|