private void FormatdgvParts(DataGridView d)
{
d.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
d.MultiSelect = false;
d.ReadOnly = true;
d.RowHeadersVisible = false;
d.AllowUserToAddRows = false;
}
private void FormatdgvProds(DataGridView d)
{
d.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
d.MultiSelect = false;
d.ReadOnly = true;
d.RowHeadersVisible = false;
d.AllowUserToAddRows = false;
}
private void Display()
{
dgvParts.AutoGenerateColumns = true;
dgvParts.DataSource = Inventory.AllParts;
dgvProds.AutoGenerateColumns = true;
dgvProds.DataSource = Inventory.Products;
}
public Form1()
{
InitializeComponent();
FormatdgvParts(dgvParts);
FormatdgvProds(dgvProds);
Display();
}
Any ideas on how to not get the first row selected when it loads?
I've tried d.CurrentRow.Selected = false; - threw an exception
d.Rows[0].Selected = false; - threw same exception
Related
I have a ComboBox called Number of Candidates and I have 10 other comboBoxes, Upon selecting the number of candidates from the drop down menu that 10 ComboBoxes should be shown or hidden.
For example : I select number of candidates as 3 then ComboBox1 ComboBox2, ComboBox3 should be visible. If I select 2 then only ComboBox1 and ComboBox2 should be visible, rest should be hidden.
I have written below code which works fine for step up like 2 to 3, 3 to 5 like that.. For step down like 4 to 2 it won't work. Could you guys please help me
private void noOfCandidates_SelectedIndexChanged(object sender, EventArgs e)
{
int value = Convert.ToInt16(noOfCandidates.SelectedItem);
if (value == 1)
{
candidateBox1.Visible = true; candidate2lbl.Visible = true;
}
else if (value == 2)
{
candidateBox1.Visible = true; candidate2lbl.Visible = true;
candidateBox2.Visible = true; candidate3lbl.Visible = true;
}
else if (value == 3)
{
candidateBox1.Visible = true; candidate2lbl.Visible = true;
candidateBox2.Visible = true; candidate3lbl.Visible = true;
candidateBox3.Visible = true; candidate4lbl.Visible = true;
}
else if (value == 4)
{
candidateBox1.Visible = true; candidate2lbl.Visible = true;
candidateBox2.Visible = true; candidate3lbl.Visible = true;
candidateBox3.Visible = true; candidate4lbl.Visible = true;
candidateBox4.Visible = true; candidate5lbl.Visible = true;
}
}
use this code :
private void noOfCandidates_SelectedIndexChanged(object sender, EventArgs e)
{
int value = Convert.ToInt16(noOfCandidates.SelectedItem);
if (value == 1)
{
candidateBox1.Visible = true; candidate2lbl.Visible = true;
candidateBox2.Visible = false; candidate3lbl.Visible = false;
candidateBox3.Visible = false; candidate4lbl.Visible = false;
candidateBox4.Visible = false; candidate5lbl.Visible = false;
}
else if (value == 2)
{
candidateBox1.Visible = true; candidate2lbl.Visible = true;
candidateBox2.Visible = true; candidate3lbl.Visible = true;
candidateBox3.Visible = false; candidate4lbl.Visible = false;
candidateBox4.Visible = false; candidate5lbl.Visible = false;
}
else if (value == 3)
{
candidateBox1.Visible = true; candidate2lbl.Visible = true;
candidateBox2.Visible = true; candidate3lbl.Visible = true;
candidateBox3.Visible = true; candidate4lbl.Visible = true;
candidateBox4.Visible = false; candidate5lbl.Visible = false;
}
else if (value == 4)
{
candidateBox1.Visible = true; candidate2lbl.Visible = true;
candidateBox2.Visible = true; candidate3lbl.Visible = true;
candidateBox3.Visible = true; candidate4lbl.Visible = true;
candidateBox4.Visible = true; candidate5lbl.Visible = true;
}
}
I hope it was useful.
i have a method that enabling and disabling button in here.My if-else block should do when enter a number to lbDivide the 'öde', '0' and '00' buttons should be active but only activing öde button.How do i solve this ?
öde = make payment
Kişi Sayısı = How many person?
private void Bol_Click(object sender, RoutedEventArgs e)
{
lbDivide.Text = "0";
btnBol.Opacity = 0.5;
btnBol.IsEnabled = false;
lbPayment.Visibility = Visibility.Hidden;
if (lbDivide.Text == "0")
{
btnQr.Opacity = 0.5;
btnQr.IsEnabled = false;
zero.Opacity = 0.2;
zero.IsEnabled = false;
double_zero.IsEnabled = false;
double_zero.Opacity = 0.2;
}
else
{
btnQr.Opacity = 1;
btnQr.IsEnabled = true;
zero.Opacity = 1;
double_zero.Opacity = 1;
zero.IsEnabled = true;
double_zero.IsEnabled = true;
}
I think I know where the error is.
private void Bol_Click(object sender, RoutedEventArgs e)
{
lbDivide.Text = "0"; /// in this line of code you're basically setting lbDivide.text to be 0 every time the button is clicked, so the else condition will never be met.
btnBol.Opacity = 0.5;
btnBol.IsEnabled = false; /// you're basically disabling the button after the first click.
lbPayment.Visibility = Visibility.Hidden;
if (lbDivide.Text == "0")
{
btnQr.Opacity = 0.5;
btnQr.IsEnabled = false;
zero.Opacity = 0.2;
zero.IsEnabled = false;
double_zero.IsEnabled = false;
double_zero.Opacity = 0.2;
}
else
{
btnQr.Opacity = 1;
btnQr.IsEnabled = true;
zero.Opacity = 1;
double_zero.Opacity = 1;
zero.IsEnabled = true;
double_zero.IsEnabled = true;
}
}
change if(lbDivide.Text == "0") by if(lbDivide.Text.Equals("0"))
As you can see I've created an array of images, but I'm not sure how to load each image into successive indexes.
Someone told me to do this for my game but I'm not sure how or if it will fix my problem
I've made a game where the character walks left then up then down then right and a few timers that load the animation and handle the movement but when I draw using this code
*e.Graphics.DrawImage(Properties.Resources.Corn_Cobs, 70, 70, 40, 40);*
My character gets really laggy/slow but when I don't draw the image it works smoothly and the character speeds up like normal.
Here is the code:
namespace Rice_Boy_Tester_2
{
public partial class Form1 : Form
{
bool iggy = false;
bool left2 = false;
bool right2 = false;
bool Up2 = false;
bool Down2 = false;
bool Check2 = false;
bool left = false;
bool right = false;
bool Up = false;
bool Down = false;
bool Check = false;
Image[] Animations;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Animations = new Image[6];
Animations[0] = Image.FromFile("Rice-Boy-Walking-Left-Bouncing.gif");
Animations[1] = Image.FromFile("Rice-Boy-Walking-Up-Bouncing.gif");
Animations[2] = Image.FromFile("Rice-Boy-Walking-Right-Bouncing.gif");
Animations[3] = Image.FromFile("Rice-Boy-Walking-Down.gif");
Animations[4] = Properties.Resources.Rice_Boy_Standing_Left;
Animations[5] = Properties.Resources.Corn_Cobs;
}
private void Refresh_Tick(object sender, EventArgs e)
{
this.Refresh();
}
private void PriceBoyWalk_Tick(object sender, EventArgs e)
{
if (left)//Goes Left
{
Player.Left -= 1;
}
if (Player.Left < 170 & Check == false)//checks how far away player is from form
{
left = false;
Up = true;
}
if (Up & Player.Left < 170) //Goes Up
{
Player.Top -= 1;
Check = true;
}
if (Player.Top < 100 & Check)
{
Up = false;
Down = true;
}
if (right)//Goes Right
{
Player.Left += 1;
}
if (Down)//Goes Down
{
Player.Top += 1;
}
if (Player.Top + 150 > this.ClientSize.Height)// When RiceBoy goes down and hits bottom right = true
{
Check = false;
Down = false;
right = true;
}
if (Player.Left + 150 > this.ClientSize.Width)//Stops At Starting Point
{
right = false;
}
}
private void B1_Click(object sender, EventArgs e)
{
this.Paint += new PaintEventHandler(form1_Pad1_Corn);
RiceBoyWalkGif.Enabled = true;
left = true;
left2 = true;
RiceBoyWalk.Enabled = true;}
}
private void form1_Pad1_Corn(object sender, System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawImage(Properties.Resources.Corn_Cobs, 70, 70, 400, 400);
}
private void timer1_Tick(object sender, EventArgs e)
{
if (left2)
{
Player.Image = Animations[0];
left2 = false;
}
if (Player.Left < 170 & Check2 == false)//checks how far away player is from form
{
left2 = false;
Up2 = true;
}
if (Up2 & Player.Left < 170) //Goes Up
{
this.Player.Size = new System.Drawing.Size(36, 76); // Changes size of the picture box to maintain quaility
Player.Image = Animations[1];//Animates RiceBoyWalkingUp
Check2 = true;
Up2 = false;
}
if (Player.Top < 105 & Check2)//Player.Top < 101 must be +1 greater than the RiceBoyWalkTimer
{
Up2 = false;
Down2 = true;
}
if (right2)
{
this.Player.Size = new System.Drawing.Size(53, 77); // Changes size of the picture box to maintain quaility
Player.Image = Animations[2];//Animates RiceBoyWalkingRight
right2 = false;
}
if (Down2)//Goes Down
{
Player.Image = Animations[3];//Animates RiceBoyWalkingDown
Down2 = false;
}
if (Player.Top + 150 > this.ClientSize.Height)// When RiceBoy goes down and hits bottom riceboy walks right
{
iggy = true;// shows that riceboy is approching the starting point
Check2 = false;
Down2 = false;
right2 = true;
}
if (Player.Left + 150 > this.ClientSize.Width & iggy)//Stops At Starting Point
{
right2 = false;
Player.Image = Animations[4];// Rice boy standing left
}
I created a program what will type a text for me automatically by using SendKeys command. When I press start button the text will be typed as it should, and when I press start button the text will stop from typing. The typing is done by using an interval timer which will decide when to start typing and have a brief space between typing 2 lines.
The problem is that when I start typing and type part of the message then press stop before program can type the entire message then start typing again, the message will continue to type from where it stopped. For example I want to type the message "123456789". I start typing then program types "1234" then press stop so program wont type no more. Then when I press start again program should start typing from 1, but instead my program types "56789".
How to reset the line when I stop, then start again? I tried to make the message as a "message" variable which is reset when I press stop button but it doesn't work.
This is how I set to type every interval tick:
private void Space(object sender, EventArgs e)
{
if (cbRandomLine.Checked || tickCount < lbMessage.Items.Count)
{
var index = cbRandomLine.Checked ? randomLine : tickCount;
var item = lbMessage.Items[index].ToString();
SendKeys.Send(item.Substring(currentChar++, 1));
if (currentChar == item.Length)
{
SendKeys.Send("{enter}");
tmrSpace.Enabled = false;
currentChar = 0;
}
}
tmrSpace.Interval = random.Next(10, 100);
}
private void Delay(object sender, EventArgs e)
{
if (delayCount == 0)
{
tmrDelay.Stop();
tmrInterval.Start();
lblDelay.Text = "Typing...";
}
else lblDelay.Text = "Typing in: " + delayCount;
delayCount--;
}
// METHODS
private void WhenStarted()
{
tickCount = 0;
delayCount = 2;
lbMessage.Enabled = false;
txtMessage.Enabled = false;
if (cbDelay.Checked)
{
lblDelay.Text = "Typing...";
tmrInterval.Enabled = true;
}
else
{
lblDelay.Text = "Typing in: 3";
tmrDelay.Enabled = true;
}
cbPause.Enabled = false;
cbDelay.Enabled = false;
cbRandomLine.Enabled = false;
btnStart.Enabled = false;
btnStop.Enabled = true;
btnStop.Focus();
}
private void WhenStopped()
{
lblDelay.Text = string.Empty;
whenStart = false;
tickCount = 0;
txtMessage.Text = string.Empty;
lbMessage.Enabled = true;
txtMessage.Enabled = true;
cbPause.Enabled = true;
cbDelay.Enabled = true;
cbRandomLine.Enabled = true;
btnStart.Enabled = true;
btnStop.Enabled = false;
btnStart.Focus();
tmrDelay.Enabled = false;
tmrInterval.Enabled = false;
tmrSpace.Enabled = false;
}
private void SetInterval()
{
if (nudPlusMinus.Value == 0)
{
tmrInterval.Interval = int.Parse(nudInterval.Value.ToString());
}
else
{
tmrInterval.Interval = random.Next(int.Parse(nudInterval.Value.ToString()) - int.Parse(nudPlusMinus.Value.ToString()), int.Parse(nudInterval.Value.ToString()) + int.Parse(nudPlusMinus.Value.ToString()));
}
}
private void ListBoxContentCheck()
{
if (lbMessage.Items.Count > 0)
{
btnStart.Enabled = true;
}
else
{
btnStart.Enabled = false;
}
}
You need to reset the currentChar variable.
I using this code for sum selected cells. Its work good but when user selecte cell where is letter is throws exceptions : ) how can i secure when in selectet cells is letters dont make sum
private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
String filterStatus = DataGridViewAutoFilterColumnHeaderCell.GetFilterStatus(dataGridView1);
if (String.IsNullOrEmpty(filterStatus))
{
showAllLabel.Visible = false;
filterStatusLabel.Visible = false;
}
else
{
int result = -1;
Int32.TryParse(filterStatus, out result);
if (result != 0)
{
// it is a number
showAllLabel.Visible = true;
filterStatusLabel.Visible = true;
filterStatusLabel.Text = filterStatus;
}
else
{
// it can be a number yet won't help you with adding
}
}
}
this is my code
private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
String filterStatus = DataGridViewAutoFilterColumnHeaderCell.GetFilterStatus(dataGridView1);
if (String.IsNullOrEmpty(filterStatus))
{
showAllLabel.Visible = false;
filterStatusLabel.Visible = false;
}
else
{
showAllLabel.Visible = true;
filterStatusLabel.Visible = true;
filterStatusLabel.Text = filterStatus;
}
}