Hi, I have code that reads and writes to a COM port. When the program reads from the COM port it searches for a string value and puts it in a variable. After it does this, it again listens to the COM port. I need to write to the COM port and read some new data, but I'm not seeing the value has changing to a new value.
Here is my code:
private void timer1_Tick(object sender, EventArgs e)
{
sq = "777";
if (CommunicationManager.myQ.Count != 0)
{
sq = CommunicationManager.myQ.Dequeue().ToString();
textBox1.Text = sq + textBox1.Text;
buffer = Regex.Match(textBox1.Text, #"\
((.+?)\,15,").Groups[1].Value;
}
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i <= numtst; i++)
{
listView1.Items[i].BackColor = Color.White;
fl[i] = false;
}
nt = 0;
flon = false;
flag[0] = false;
comm.WriteData("AT\r\n");
wait(700);
if (buffer.lenght == 16)
{
flag[0] = true
}
if (flag[0] == true)
{
flon = true;
CommunicationManager.myQ.Clear();
break;
}
}
if (flon == true)
{
listView1.Items[nt].BackColor = Color.LightGreen;
fl[nt] = true;
}
else
{
listView1.Items[nt].BackColor = Color.Red;
if (flag[76] == true)
{
button1.Enabled = true;
button1.BackColor = Color.Red;
button1.Text = "Test ERROR";
return;
}
}
comm.WriteData("ATT\r\n");
wait(3700);
comm.WriteData("AT4\r\n");
nt = 1;
flon = false;
flag[1] = false;
if (buffer == text4.text)
{
flag[1] = true
}
wait(700);
if (flag[1] == true)
{
flon = true;
CommunicationManager.myQ.Clear();
break;
}
if (flag[76] == true)
{
button1.Enabled = true;
return;
}
}
if (flon == true)
{
listView1.Items[nt].BackColor = Color.LightGreen;
fl[nt] = true;
}
else
{
listView1.Items[nt].BackColor = Color.Red;
if (flag[76] == true)
{
button1.Enabled = true;
button1.BackColor = Color.Red;
button1.Text = "Test ERROR";
return;
}
}
in the second part if (buffer == text4.text) i see only first value of the buffer variable.
i checked in the terminal and all commands working good.
Related
I have this simple snake game, my problem is that the tails wont add when it reaches three tails.
namespace Snake
{
public partial class Form1 : Form
{
bool left = false, right = false;
bool top = false, down = false;
PictureBox pic = new PictureBox();
List<PictureBox> tails = new List<PictureBox>();
int score = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (((e.KeyChar.ToString() == "a") || (e.KeyChar.ToString() == "A"))&&(right == false))
{
right = false;
top = false;
down = false;
left = true;
}
else if (((e.KeyChar.ToString() == "d") || (e.KeyChar.ToString() == "D"))&& (left == false))
{
top = false;
down = false;
left = false;
right = true;
}
else if (((e.KeyChar.ToString() == "w") || (e.KeyChar.ToString() == "W"))&& (down == false))
{
down = false;
left = false;
right = false;
top = true;
}
else if (((e.KeyChar.ToString() == "s") || (e.KeyChar.ToString() == "S"))&& (top == false))
{
top = false;
left = false;
right = false;
down = true;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
//ticks every 1 sec
if (pic.Location == head.Location)
{
score++;
spawnFood();
tails.Add(addTails());
}
sortLocation();
if (right == true)
{
int r = head.Location.X + head.Height;
head.Location = new Point(r, head.Location.Y);
}
else if(left == true)
{
int l = head.Location.X - head.Height;
head.Location = new Point(l, head.Location.Y);
}
else if (top == true)
{
int t = head.Location.Y - head.Height;
head.Location = new Point(head.Location.X, t);
}
else if (down == true)
{
int d = head.Location.Y + head.Height;
head.Location = new Point(head.Location.X,d);
}
txtScore.Text = score.ToString();
}
private void sortLocation()
{
if (tails.Count == 0)
{
}
else
{
for (int i = 1; i < tails.Count; i++)
{
tails[i].Location = tails[i-1].Location;
}
tails[0].Location = head.Location;
}
}
private PictureBox addTails()
{
PictureBox tail = new PictureBox();
tail.Name = "tail" + score.ToString();
tail.BackColor = Color.Black;
tail.Width = 10;
tail.Height = 10;
this.Controls.Add(tail);
return tail;
}
private void spawnFood()
{
Random rnd = new Random();
int rndLocationX = rnd.Next(10, 50);
int rndLocationY = rnd.Next(10, 50);
pic.BackColor = Color.Red;
pic.Height = 10;
pic.Width = 10;
this.Controls.Add(pic);
if (rndLocationX >= 500)
{
rndLocationX -= 10;
}
if (rndLocationY >= 500)
{
rndLocationY -= 10;
}
pic.Location = new Point(rndLocationX*10,rndLocationY*10);
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
spawnFood();
}
}
}
for (int i = 1; i < tails.Count; i++)
{
tails[i].Location = tails[i+1].Location;
}
tails[0].Location = head.Location;
Are your tails there just stacked so to speak? That's another thought I might be thinking. I changed the tails[i-1] to tails [i+1]. Check if that does the trick.
Is there a way to group 30+ labels to be able to control them all at once. What I want to do is this with 30 labels.
if (player.Bounds.IntersectsWith(label1.Bounds))
{
if (right == true)
{
right = false;
left = true;
}
else if (left == true)
{
left = false;
right = true;
}
else if (up == true)
{
up = false;
down = true;
}
else if (down == true)
{
down = false;
up = true;
}
And then where the label1 is checking if it is colided I want it to check all 30 labels if they have colided. And preferably not with 30x this code and just change the number. =)
I just want to add this is a maze game and the left, right etc. is the players movement defined outside what I posted here. I hope you understand!
All of my code:
namespace mazeGame
{
public partial class Form1 : Form
{
bool down;
bool left;
bool right;
bool up;
// new List<int> blocks = new List[5];
public Form1()
{
InitializeComponent();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
if (label1.Bounds.IntersectsWith(label10.Bounds))
{
}
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
{
down = false;
up = false;
right = true;
left = false;
}
if (e.KeyCode == Keys.Left)
{
left = true;
down = false;
up = false;
right = false;
}
if (e.KeyCode == Keys.Up)
{
up = true;
down = false;
right = false;
left = false;
}
if (e.KeyCode == Keys.Down)
{
down = true;
up = false;
right = false;
left = false;
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
{
right = true;
left = false;
up = false;
down = false;
}
if (e.KeyCode == Keys.Left)
{
left = true;
right = false;
up = false;
down = false;
}
if (e.KeyCode == Keys.Up)
{
up = true;
left = false;
right = false;
down = false;
}
if (e.KeyCode == Keys.Down)
{
down = true;
left = false;
up = false;
right = false;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (player.Bounds.IntersectsWith(label1.Bounds))
{
if (right == true)
{
right = false;
left = true;
}
else if (left == true)
{
left = false;
right = true;
}
else if (up == true)
{
up = false;
down = true;
}
else if (down == true)
{
down = false;
up = true;
}
}
var labels = this.??????? // here is where i need help.
if (right == true)
{
player.Left += 1;
}
if (left == true)
{
player.Left -= 1;
}
if (up == true)
{
player.Top -= 1;
}
if (down == true)
{
player.Top += 1;
}
}
}
OfType will get all controls of the same type from a control. In this case it will be labels from your form:
var labels = this.myForm.Controls.OfType<Label>()
Then you can iterate through your collection of labels.
EDIT:
Then, looping through your code it would look like this:
private void timer1_Tick(object sender, EventArgs e)
{
var labels = this.Form1.Controls.OfType<Label>()
foreach(var label in labels)
{
if(player.Bounds.IntersectsWith(label.Bounds))
//...
As for me it is good decision to create array or even list (witch you can dynamically update) of all your 30+ labels and then to manipulate them in one short method. Of course, if the actions as much simple as you write up and nothing else.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I enable this timer in C#?
Im trying to get a little project running. When I use a break point it goes through the code correctly, but when running the program at normal speed it the sequence runs too fast. Im trying to get the traffic lights sequence to change every 1 second. What is wrong with this code? Its a simple sequence of traffic lights, incase your interested :). Newbie project.
}
public int counter = 0;
private void rbStart_CheckedChanged(object sender, EventArgs e)
{
Light_timer.Start();
counter++;
if (counter == 1)
{
pbRed.Visible = true;
pbAmber.Visible = false;
pbGreen.Visible = false;
}
else if (counter == 2)
{
pbRed.Visible = true;
pbAmber.Visible = true;
pbGreen.Visible = false;
}
else if (counter == 3)
{
pbRed.Visible = false;
pbAmber.Visible = false;
pbGreen.Visible = true;
}
else if (counter == 4)
{
pbRed.Visible = false;
pbAmber.Visible = true;
pbGreen.Visible = false;
}
else if (counter == 5)
{
pbRed.Visible = true;
pbAmber.Visible = false;
pbGreen.Visible = false;
}
else
{
counter = 0;
}
}
private void rbStop_CheckedChanged(object sender, EventArgs e)
{
pbRed.Visible = false;
pbAmber.Visible = false;
pbGreen.Visible = false;
}
private void Form1_Load(object sender, EventArgs e)
{
Light_timer.Tick += new EventHandler(rbStart_CheckedChanged);
Light_timer.Interval = 1000;
Light_timer.Stop();
}
}
}
You're hooking up the event handler every time the timer elapses and so on... Try this:
private void Form1_Load(object sender, EventArgs e)
{
Light_timer = new Timer();
Light_timer.Tick += new EventHandler(TimerElapsed);
Light_timer.Interval = 1000;
}
private void TimerElapsed(object sender, EventArgs e)
{
counter++;
if (counter == 1)
{
pbRed.Visible = true;
pbAmber.Visible = false;
pbGreen.Visible = false;
}
else if (counter == 2)
{
pbRed.Visible = true;
pbAmber.Visible = true;
pbGreen.Visible = false;
}
else if (counter == 3)
{
pbRed.Visible = false;
pbAmber.Visible = false;
pbGreen.Visible = true;
}
else if (counter == 4)
{
pbRed.Visible = false;
pbAmber.Visible = true;
pbGreen.Visible = false;
}
else if (counter == 5)
{
pbRed.Visible = true;
pbAmber.Visible = false;
pbGreen.Visible = false;
}
else
{
counter = 0;
Light_timer.Stop();
}
}
private void rbStart_CheckedChanged(object sender, EventArgs e)
{
Light_timer.Start();
}
private void rbStop_CheckedChanged(object sender, EventArgs e)
{
Light_timer.Stop();
pbRed.Visible = false;
pbAmber.Visible = false;
pbGreen.Visible = false;
}
I built a WinForm app that works fine with SQL database stored online. I am now trying to move to asp.net app. After learning everything I needed to build the WinForm app I am frustrated over new learning curve!
This is a basic app that has a listbox with all people in the database. The listbox display the combined NameLast + ‘, ‘ + NameFirst as NameFull showing something like “Smith, John”. When the user selects a person the textboxes should display the related information. Once I get started it should be easy however… How do I build a OnSelectedChanged type command to fill the textboxes. In this example I would have four (4) textboxes: NameFirstTxt, NameMiddleTxt, NameLastTxt and RecordIDTxt.
I have attached code from the WinForm app used during the selected index change event.
Any advice and comments (good or bad) would be helpful. Thank you in advance.
private void peopleDetailsDirectoryLbx_SelectedIndexChanged(object sender, EventArgs e)
{
peopleDirectoryGbx.Text = "People Records : " + peopleDetailsDirectoryLbx.Items.Count.ToString();
DataRowView PeopleRow = peopleDetailsDirectoryLbx.SelectedItem as DataRowView;
if (PeopleRow != null && PeopleRow.Row != null && PeopleRow.Row.ItemArray != null)
{
DataRow row = PeopleRow.Row;
if (row.ItemArray.Count() > 0)
try
{
peopleDetailsIDTxt.Text = Convert.ToString(row["ID"]).ToString();
try
{
peopleDetailsPhotoImg.Load(#"http://www.officertech.com/PeoplePhotoBase/" + peopleDetailsIDTxt.Text + ".jpg");
}
catch
{
peopleDetailsPhotoImg.Load(#"http://www.officertech.com/PeoplePhotoBase/NoPhoto.jpg");
}
if (Convert.ToString(row["Active"].ToString()) == "True")
{
peopleDetailsActiveChk.Checked = true;
}
else
{
peopleDetailsActiveChk.Checked = false;
}
peopleDetailsNameFirstTxt.Text = (row["NameFirst"]).ToString();
peopleDetailsNameMiddleTxt.Text = (row["NameMiddle"]).ToString();
peopleDetailsNameLastTxt.Text = (row["NameLast"]).ToString();
peopleDetailsNameAka1Txt.Text = (row["NameAKA1"]).ToString();
peopleDetailsNameAka2Txt.Text = (row["NameAKA2"]).ToString();
peopleDetailsDobTxt.Text = Convert.ToDateTime(row["DOB"]).ToShortDateString();
peopleDetailsRaceCbx.Text = (row["Race"]).ToString();
peopleDetailsGenderCbx.Text = (row["Gender"]).ToString();
peopleDetailsAddStreetNumTxt.Text = (row["AddStreetNum"]).ToString();
peopleDetailsStreetNameCbx.Text = (row["AddStreetName"]).ToString();
peopleDetailsAddCityTxt.Text = (row["AddCity"]).ToString();
peopleDetailsAddStateTxt.Text = (row["AddState"]).ToString();
peopleDetailsAddZipTxt.Text = (row["AddZip"]).ToString();
peopleDetailsAddCountyTxt.Text = (row["AddCounty"]).ToString();
peopleDetailsDriverLicenseTxt.Text = (row["DriverLicense"]).ToString();
peopleDetailsDriverLicenseStateTxt.Text = (row["DriverLicenseState"]).ToString();
peopleDetailsSSNTxt.Text = (row["SSN"]).ToString();
peopleDetailsTrackingLab.ForeColor = Color.Black;
if (row["Tracking"].ToString() == "True")
{
peopleDetailsTrackingYesRad.Checked = true;
peopleDetailsTrackingLab.ForeColor = Color.Red;
}
else
{
peopleDetailsTrackingNoRad.Checked = true;
peopleDetailsTrackingLab.ForeColor = Color.Black;
}
peopleDetailsPhysIDColorHairCbx.Text = (row["PhysIDColorHair"].ToString());
peopleDetailsPhysIDColorEyesCbx.Text = (row["PhysIDColorEyes"].ToString());
peopleDetailsPhysIDWeightTxt.Text = (row["PhysIDWeight"].ToString());
peopleDetailsPhysIDHeightTxt.Text = (row["PhysIDHeight"].ToString());
peopleDetailsPhysIDScarTattTxt.Text = (row["PhysIDScarTatt"].ToString());
//////
if (Convert.ToString(row["School"].ToString()) == "True")
{
peopleDetailsSchoolRad.Checked = true;
}
else
{
peopleDetailsSchoolRad.Checked = false;
}
//////
if (Convert.ToString(row["Work"].ToString()) == "True")
{
peopleDetailsWorkRad.Checked = true;
}
else
{
peopleDetailsWorkRad.Checked = false;
}
//////
if (Convert.ToString(row["ciAssault"].ToString()) == "True")
{
peopleCIAssaultChk.Checked = true;
peopleCIAssaultChk.ForeColor = Color.Red;
}
else
{
peopleCIAssaultChk.Checked = false;
peopleCIAssaultChk.ForeColor = Color.Black;
}
//////
peopleDetailsSchoolWorkNameTxt.Text = (row["SchoolWorkName"]).ToString();
//////
if (Convert.ToString(row["ciBattery"].ToString()) == "True")
{
peopleCIBatteryChk.Checked = true;
peopleCIBatteryChk.ForeColor = Color.Red;
}
else
{
peopleCIBatteryChk.Checked = false;
peopleCIBatteryChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciBatteryAgg"].ToString()) == "True")
{
peopleCIBatteryAggChk.Checked = true;
peopleCIBatteryAggChk.ForeColor = Color.Red;
}
else
{
peopleCIBatteryAggChk.Checked = false;
peopleCIBatteryAggChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciBatteryDVR"].ToString()) == "True")
{
peopleCIBatteryDVRChk.Checked = true;
peopleCIBatteryDVRChk.ForeColor = Color.Red;
}
else
{
peopleCIBatteryDVRChk.Checked = false;
peopleCIBatteryDVRChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciBatteryLEO"].ToString()) == "True")
{
peopleCIBatteryLEOChk.Checked = true;
peopleCIBatteryLEOChk.ForeColor = Color.Red;
}
else
{
peopleCIBatteryLEOChk.Checked = false;
peopleCIBatteryLEOChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciBurglary"].ToString()) == "True")
{
peopleCIBurglaryChk.Checked = true;
peopleCIBurglaryChk.ForeColor = Color.Red;
}
else
{
peopleCIBurglaryChk.Checked = false;
peopleCIBurglaryChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciChildCrimes"].ToString()) == "True")
{
peopleCIChildCrimeChk.Checked = true;
peopleCIChildCrimeChk.ForeColor = Color.Red;
}
else
{
peopleCIChildCrimeChk.Checked = false;
peopleCIChildCrimeChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciCrimMisch"].ToString()) == "True")
{
peopleCICrimMischChk.Checked = true;
peopleCICrimMischChk.ForeColor = Color.Red;
}
else
{
peopleCICrimMischChk.Checked = false;
peopleCICrimMischChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciDealStolen"].ToString()) == "True")
{
peopleCIDealStolenChk.Checked = true;
peopleCIDealStolenChk.ForeColor = Color.Red;
}
else
{
peopleCIDealStolenChk.Checked = false;
peopleCIDealStolenChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciDisorderly"].ToString()) == "True")
{
peopleCIDisorderlyChk.Checked = true;
peopleCIDisorderlyChk.ForeColor = Color.Red;
}
else
{
peopleCIDisorderlyChk.Checked = false;
peopleCIDisorderlyChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciDrugs"].ToString()) == "True")
{
peopleCIDrugsChk.Checked = true;
peopleCIDrugsChk.ForeColor = Color.Red;
}
else
{
peopleCIDrugsChk.Checked = false;
peopleCIDrugsChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciDUI"].ToString()) == "True")
{
peopleCIDUIChk.Checked = true;
peopleCIDUIChk.ForeColor = Color.Red;
}
else
{
peopleCIDUIChk.Checked = false;
peopleCIDUIChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciDWLSR"].ToString()) == "True")
{
peopleCIDWLSRChk.Checked = true;
peopleCIDWLSRChk.ForeColor = Color.Red;
}
else
{
peopleCIDWLSRChk.Checked = false;
peopleCIDWLSRChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciFraud"].ToString()) == "True")
{
peopleCIFraudChk.Checked = true;
peopleCIFraudChk.ForeColor = Color.Red;
}
else
{
peopleCIFraudChk.Checked = false;
peopleCIFraudChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciHomicide"].ToString()) == "True")
{
peopleCIHomicideChk.Checked = true;
peopleCIHomicideChk.ForeColor = Color.Red;
}
else
{
peopleCIHomicideChk.Checked = false;
peopleCIHomicideChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciLewdLasciv"].ToString()) == "True")
{
peopleCILewdLascivChk.Checked = true;
peopleCILewdLascivChk.ForeColor = Color.Red;
}
else
{
peopleCILewdLascivChk.Checked = false;
peopleCILewdLascivChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciMental"].ToString()) == "True")
{
peopleCIMentalChk.Checked = true;
peopleCIMentalChk.ForeColor = Color.Red;
}
else
{
peopleCIMentalChk.Checked = false;
peopleCIMentalChk.ForeColor = Color.Black;
}
//////
peopleCIProbationLab.ForeColor = Color.Black;
if (row["ciProbation"].ToString() == "True")
{
peopleCIProbationYesRad.Checked = true;
peopleCIProbationLab.ForeColor = Color.Red;
}
else
{
peopleCIProbationNoRad.Checked = true;
peopleCIProbationLab.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciResisting"].ToString()) == "True")
{
peopleCIResistingChk.Checked = true;
peopleCIResistingChk.ForeColor = Color.Red;
}
else
{
peopleCIResistingChk.Checked = false;
peopleCIResistingChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciRobbery"].ToString()) == "True")
{
peopleCIRobberyChk.Checked = true;
peopleCIRobberyChk.ForeColor = Color.Red;
}
else
{
peopleCIRobberyChk.Checked = false;
peopleCIRobberyChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciSexCrime"].ToString()) == "True")
{
peopleCISexCrimeChk.Checked = true;
peopleCISexCrimeChk.ForeColor = Color.Red;
}
else
{
peopleCISexCrimeChk.Checked = false;
peopleCISexCrimeChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciShoplift"].ToString()) == "True")
{
peopleCIShopLiftChk.Checked = true;
peopleCIShopLiftChk.ForeColor = Color.Red;
}
else
{
peopleCIShopLiftChk.Checked = false;
peopleCIShopLiftChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciTheft"].ToString()) == "True")
{
peopleCITheftChk.Checked = true;
peopleCITheftChk.ForeColor = Color.Red;
}
else
{
peopleCITheftChk.Checked = false;
peopleCITheftChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciTraffic"].ToString()) == "True")
{
peopleCITrafficChk.Checked = true;
peopleCITrafficChk.ForeColor = Color.Red;
}
else
{
peopleCITrafficChk.Checked = false;
peopleCITrafficChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciTrespass"].ToString()) == "True")
{
peopleCITrespassChk.Checked = true;
peopleCITrespassChk.ForeColor = Color.Red;
}
else
{
peopleCITrespassChk.Checked = false;
peopleCITrespassChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciWarrants"].ToString()) == "True")
{
peopleCIWarrantsChk.Checked = true;
peopleCIWarrantsChk.ForeColor = Color.Red;
}
else
{
peopleCIWarrantsChk.Checked = false;
peopleCIWarrantsChk.ForeColor = Color.Black;
}
//////
if (Convert.ToString(row["ciWeapons"].ToString()) == "True")
{
peopleCIWeaponsChk.Checked = true;
peopleCIWeaponsChk.ForeColor = Color.Red;
}
else
{
peopleCIWeaponsChk.Checked = false;
peopleCIWeaponsChk.ForeColor = Color.Black;
}
//////
CalcAge_People();
//arrestFieldsFill();
}
catch (Exception ex)
{
MessageBox.Show("Problem Locating Person Information" + ex, "CARDS 2012 | Message Center", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
Make sure the AutoPostback property of ListBox is set to true.
Aspx Code:
<asp:ListBox ID="ListBox1" runat="server" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged"
AutoPostBack="True">
<asp:ListItem>1st Person</asp:ListItem>
<asp:ListItem>2nd Person</asp:ListItem>
<asp:ListItem>3rd person</asp:ListItem>
</asp:ListBox>
<br />
FIRST NAME:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
LASTNAME:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
EMAIL:<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
Code behind:
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (ListItem li in ListBox1.Items)
{
if (li.Selected == true)
{
// what ever you want to assign to TextBox
this.TextBox1.Text = li.Text + "First Name"; // (row["NameFirst"]).ToString();
this.TextBox2.Text = li.Text + "Last Name";
this.TextBox3.Text = li.Text + "Email";
}
}
}
Hope this Helps.
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;
}
}