How to display value from not selected combobox c# - c#

I need to display an unselected ComboBox value.
I have 10 ComboBoxes with tag values 1 through 10.
When I select a ComboBox with a tag value of 1, I have to check what is displayed from the ComboBox that has a tag value of 2.
Selecting a ComboBox with a tag value of 5 should give me the value of the ComboBox that has a tag value of 6.
public partial class workPlacePlan : Form
{
public workPlacePlan()
{
InitializeComponent();
}
private void workPlacePlan_Load(object sender, EventArgs e)
{
this.MaximumSize = this.Size;
this.MinimumSize = this.Size;
int cboId;
int i = 1;
string cboName; int c = 1;
var items = new Dictionary<int, string>();
ComboBox[] cbo = {
cbo_1, cbo_2
};
foreach(ComboBox cbos in cbo)
{
items.Add(0, "-------");
i = 1;
while (i <= 24)
{
cboId = i;
cboName = TimeSpan.FromHours(i).ToString("hh':'mm");
items.Add(cboId, cboName);
i++;
}
cbos.Tag = c;
cbos.DataSource = new BindingSource(items, null);
cbos.DisplayMember = "Value";
cbos.ValueMember = "Key";
items.Clear();
cbos.SelectedIndexChanged += new EventHandler(cboSelected);
c++;
}
}
public void cboSelected(object sender, EventArgs e)
{
ComboBox cb = ((ComboBox)sender);
int i_tmp;
int tg = Int32.Parse(cb.Tag.ToString());
if(tg % 2 == 0) //if is even
{
i_tmp= tg - 1;
}
else
{
i_tmp = tg + 1;
}
}
private void cmd_Save_Click(object sender, EventArgs e)
{
}
}

Solution:
public partial class workPlacePlan : Form
{
public workPlacePlan()
{
InitializeComponent();
}
private void workPlacePlan_Load(object sender, EventArgs e)
{
this.MaximumSize = this.Size;
this.MinimumSize = this.Size;
int cboId;
int i = 1;
string cboName; int c = 1;
var items = new Dictionary<int, string>();
ComboBox[] cbo = {
cbo_1_0, cbo_1_1, cbo_2_0, cbo_2_1, cbo_3_0, cbo_3_1, cbo_4_0, cbo_4_1, cbo_5_0, cbo_5_1, cbo_6_0, cbo_6_1,
cbo_13_0,cbo_13_1,cbo_14_0,cbo_14_1,cbo_15_0,cbo_15_1,cbo_16_0,cbo_16_1,cbo_17_0,cbo_17_1,cbo_18_0,cbo_18_1,
cbo_19_0,cbo_19_1
};
foreach(ComboBox cbos in cbo)
{
items.Add(0, "-------");
i = 1;
while (i <= 24)
{
cboId = i;
cboName = TimeSpan.FromHours(i).ToString("hh':'mm");
items.Add(cboId, cboName);
i++;
}
cbos.Tag = c;
cbos.DataSource = new BindingSource(items, null);
cbos.DisplayMember = "Value";
cbos.ValueMember = "Key";
cbos.SelectedIndex = 0;
items.Clear();
cbos.SelectedIndexChanged += new EventHandler(cboSelected);
c++;
}
}
public void cboSelected(object sender, EventArgs e)
{
ComboBox cb = ((ComboBox)sender);
int i_tmp;
int tg = Int32.Parse(cb.Tag.ToString());
int idx;
if(tg % 2 == 0) //if is even
{
i_tmp= tg - 1;
}
else
{
i_tmp = tg + 1;
}
//string y = cb.GetItemText(cb.SelectedItem);
//MessageBox.Show(y.ToString());
foreach (ComboBox cbt in panel1.Controls.OfType<ComboBox>()) {
if(Int32.Parse(cbt.Tag.ToString()) == Int32.Parse(i_tmp.ToString()))
{
idx = Int32.Parse(cbt.SelectedIndex.ToString());
cbt.SelectedIndex = idx;
MessageBox.Show(cbt.SelectedIndex.ToString());
}
}
}
private void cmd_Save_Click(object sender, EventArgs e)
{
}
}

Related

Customize TextBox autocomplete

How do I change the autocomplete on a TextBox? I want that when I type a string, the box suggest items containing that string instead of starting with.
My code is:
class MyClass
{
private AutoCompleteStringCollection autoCompleteList = new AutoCompleteStringCollection();
public MyClass()
{
InitializeComponent();
autoCompleteList.AddRange(ListNames.Select(x=>x.Name).ToArray());
textBoxName.AutoCompleteCustomSource = autoCompleteList;
textBoxName.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBoxName.AutoCompleteMode = AutoCompleteMode.Suggest;
textBoxName.KeyDown += TextBoxtextName_KeyDown;
}
private void TextBoxClient_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
this.Name = (sender as TextBox).Text;
}
}
}
What I want:
Looking at your code you have everything you need but 1 line of code. That line is:
This will only work if the start of a string is entered
//Suggestion only
textBoxName.AutoCompleteMode = AutoCompleteMode.Suggest;
//Suggest and autocomplete
textBoxName.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
This will work as a contains method but works with a custom control
You can also make a custom textbox control that fits your needs.
Custom textbox class:
public class AutoCompleteTextBox : TextBox
{
private ListBox _listBox;
private bool _isAdded;
private String[] _values;
private String _formerValue = String.Empty;
public AutoCompleteTextBox()
{
InitializeComponent();
ResetListBox();
}
private void InitializeComponent()
{
_listBox = new ListBox();
this.KeyDown += this_KeyDown;
this.KeyUp += this_KeyUp;
}
private void ShowListBox()
{
if (!_isAdded)
{
Parent.Controls.Add(_listBox);
_listBox.Left = Left;
_listBox.Top = Top + Height;
_isAdded = true;
}
_listBox.Visible = true;
_listBox.BringToFront();
}
private void ResetListBox()
{
_listBox.Visible = false;
}
private void this_KeyUp(object sender, KeyEventArgs e)
{
UpdateListBox();
}
private void this_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
case Keys.Tab:
{
if (_listBox.Visible)
{
Text = _listBox.SelectedItem.ToString();
ResetListBox();
_formerValue = Text;
this.Select(this.Text.Length, 0);
e.Handled = true;
}
break;
}
case Keys.Down:
{
if ((_listBox.Visible) && (_listBox.SelectedIndex < _listBox.Items.Count - 1))
_listBox.SelectedIndex++;
e.Handled = true;
break;
}
case Keys.Up:
{
if ((_listBox.Visible) && (_listBox.SelectedIndex > 0))
_listBox.SelectedIndex--;
e.Handled = true;
break;
}
}
}
protected override bool IsInputKey(Keys keyData)
{
switch (keyData)
{
case Keys.Tab:
if (_listBox.Visible)
return true;
else
return false;
default:
return base.IsInputKey(keyData);
}
}
private void UpdateListBox()
{
if (Text == _formerValue)
return;
_formerValue = this.Text;
string word = this.Text;
if (_values != null && word.Length > 0)
{
string[] matches = Array.FindAll(_values,
x => (x.ToLower().Contains(word.ToLower())));
if (matches.Length > 0)
{
ShowListBox();
_listBox.BeginUpdate();
_listBox.Items.Clear();
Array.ForEach(matches, x => _listBox.Items.Add(x));
_listBox.SelectedIndex = 0;
_listBox.Height = 0;
_listBox.Width = 0;
Focus();
using (Graphics graphics = _listBox.CreateGraphics())
{
for (int i = 0; i < _listBox.Items.Count; i++)
{
if (i < 20)
_listBox.Height += _listBox.GetItemHeight(i);
// it item width is larger than the current one
// set it to the new max item width
// GetItemRectangle does not work for me
// we add a little extra space by using '_'
int itemWidth = (int)graphics.MeasureString(((string)_listBox.Items[i]) + "_", _listBox.Font).Width;
_listBox.Width = (_listBox.Width < itemWidth) ? itemWidth : this.Width; ;
}
}
_listBox.EndUpdate();
}
else
{
ResetListBox();
}
}
else
{
ResetListBox();
}
}
public String[] Values
{
get
{
return _values;
}
set
{
_values = value;
}
}
public List<String> SelectedValues
{
get
{
String[] result = Text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
return new List<String>(result);
}
}
}
Usage:
string[] nameArray = { "name1", "name2", "name3", "bla name" };
AutoCompleteTextBox tb = new AutoCompleteTextBox();
tb.Values = nameArray;
tb.Location = new Point(10,10);
tb.Size = new Size(25,75);
this.Controls.Add( tb );
I got the code for the custom control from: SO Question - Autocomplete contains

Online Exam Test splits when test taken by multiple users simultaniously

My online exam application test in asp.net gets split when multiple users take the test. my 20 question test gets split into 10 10 question to each user who is taking the test simultaniously. I am using session in my appliaction here is the code please help.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using BAL;
namespace OnlineExamDesign
{
public partial class Exam : System.Web.UI.Page
{
static int index = 0;
static int selection = 0;
static int QuestionNums = 0;
clsExam examObj = new clsExam();
DataSet ds; DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
index = 0;
selection = 0;
string set = Session["CandidateSet"].ToString();
ds = examObj.getQuestion(set);
Session["Ques"] = ds;
displayQuestion(index);
btnPrevious.Enabled = false;
if (Session["candidateName"] != null)
lblCandidateName.Text = Session["candidateName"].ToString();
clearResultData();
}
}
private void clearRadioButtons()
{
rbtnOption1.Checked = false;
rbtnOption2.Checked = false;
rbtnOption3.Checked = false;
rbtnOption4.Checked = false;
}
private void clearResultData()
{
for (int n = 0; n < clsExam.AnsList.Length; n++)
{
clsExam.AnsList[n] = 0;
}
}
private void saveCandidateData()
{
Candidate obj = new Candidate();
obj.Fname = Session["CandidateFName"].ToString();
obj.Lname = Session["CandidateLName"].ToString();
obj.Contact = Session["CandidateContact"].ToString();
obj.Domain = Session["CandidateDomain"].ToString();
obj.Team = Session["CandidateTeam"].ToString();
obj.Set = Session["CandidateSet"].ToString();
obj.ExamStartTime = (DateTime)Session["strttime"];
obj.ExamEndTime = System.DateTime.Now;
obj.Score = examObj.score;
obj.actionCandidateDetails("save");
Session["Score"] = obj.Score;
}
private int displayQuestion(int index)
{
ds = (DataSet)Session["Ques"];
dt = ds.Tables[0];
int num = dt.Rows.Count;
if (index <= num)
{
lblQuestionNum.Text = Convert.ToString((index+1));
lblQuestion.Text = dt.Rows[index]["questions_question_nvc"].ToString();
rbtnOption1.Text = dt.Rows[index]["questions_option1_nvc"].ToString();
rbtnOption2.Text = dt.Rows[index]["questions_option2_nvc"].ToString();
rbtnOption3.Text = dt.Rows[index]["questions_option3_nvc"].ToString();
rbtnOption4.Text = dt.Rows[index]["questions_option4_nvc"].ToString();
}
else if (index > num - 1)
btnNext.Enabled = false;
else if (index <= 0)
btnPrevious.Enabled = false;
return num;
}
private void retainChoice()
{
if ((clsExam.AnsList[index]).Equals(1))
{
rbtnOption1.Checked = true;
}
else if ((clsExam.AnsList[index]).Equals(2))
{
rbtnOption2.Checked = true;
}
else if ((clsExam.AnsList[index]).Equals(3))
{
rbtnOption3.Checked = true;
}
else if ((clsExam.AnsList[index]).Equals(4))
{
rbtnOption4.Checked = true;
}
}
protected void btnNext_Click(object sender, EventArgs e)
{
btnPrevious.Enabled = true;
rbtnOptionCheckedChanged(sender, e);
examObj.storeAns(index, selection);
selection = 0;
clearRadioButtons();
index++;
int QuestionNums = displayQuestion(index);
retainChoice();
if (index >= QuestionNums - 1)
btnNext.Enabled = false;
}
protected void btnPrevious_Click(object sender, EventArgs e)
{
if (index > 0)
{
rbtnOptionCheckedChanged(sender, e);
examObj.storeAns(index, selection);
selection = 0;
clearRadioButtons();
index--;
displayQuestion(index);
retainChoice();
btnNext.Enabled = true;
}
else if (index <= 0)
{
btnPrevious.Enabled = false;
}
else if (index < QuestionNums - 1)
{
btnNext.Enabled = true;
}
else
{
btnPrevious.Enabled = false;
btnNext.Enabled = true;
}
}
protected void btnExit_Click(object sender, EventArgs e)
{
int i = 0;
examObj.storeAns(index, selection);
ds = (DataSet)Session["Ques"];
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (dr["questions_answer_nvc"].Equals(clsExam.AnsList[i]))
{
examObj.countScore();
i++;
}
}
Response.Write(examObj.score);
saveCandidateData();
index = 0;
clearResultData();
Response.Redirect("ThankYou.aspx");
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
int i = 0;
examObj.storeAns(index, selection);
ds = (DataSet)Session["Ques"];
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (dr["questions_answer_nvc"].Equals(clsExam.AnsList[i]))
{
examObj.countScore();
i++;
}
}
Response.Write(examObj.score);
saveCandidateData();
index = 0;
clearResultData();
Response.Redirect("ThankYou.aspx");
}
protected void rbtnOptionCheckedChanged(object sender, EventArgs e)
{
if (rbtnOption1.Checked)
selection = 1;
else if (rbtnOption2.Checked)
selection = 2;
else if (rbtnOption3.Checked)
selection = 3;
else if (rbtnOption4.Checked)
selection = 4;
}
}
}
I am going to repeat the sentence I am famous for in our company: Static is evil!
And yes, it is. static in a web application means it is shared across all users, meaning that the index of user 1 is the same as the index for user 2.
You can fix this quite easily by storing your static variables in the session object. I would simply hide that in a property:
public int Index
{
get
{
return (Session["Exam_Index"] as int?) ?? 0;
}
set
{
Session["Exam_Index"] = value;
}
}

Displaying Particular Item On listView1_MouseClick

In Quize method I am passing qestions which contains set of all my Questions to be displayed using DisplayQuestion(),Question is my Class, Problem is that I am getting only First Question displayed, how can I get them displayed when i click on listviewItem if suppose questionscontains 10 Questions,than in listviewItem I have displayed numbers(1 2 3 4 5 ....10),when i click on each number how do i display that particular Questiondisplyed on click and if not clicked how all Questions displayed one by one using timer
public partial class GroupExmStart : Form
{
string[] randomQsn = new string[totQsn + 1]; //totQsn is the total number of question for e.g.10
public GroupExmStart(string GroupName, string DurationID)
{
InitializeComponent();
this.GrpID=GroupName;
TopiID=db.GetTopicIDForGroup(GrpID);
string[] conf = db.GetConfiguration(Convert.ToInt16(DurationID)).Split('|');
Question qsn = new Question();
var questions = qsn.Foo(TopiID, conf);
int z = Quiz(questions);
totQsn = Convert.ToInt16(conf[0]);
for (int kk = 1; kk <= totQsn; kk++)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = kk.ToString();
listView1.Items.Add(lvi);
}
randomQsn = new string[totQsn + 1];
timer1.Interval = 1000; //1000ms = 1sec
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
}
int Quiz(List<Question> questions)
{
foreach (Question question in questions)
{
DisplayQuestion(question);
}
return 0;
}
private void DisplayQuestion(Question question)
{
string Q = question.Text;
label5.Text = Q;
string OP1 = question.Option1;
string OP2 = question.Option2;
string OP3 = question.Option3;
string OP4 = question.Option4;
radioButton12.Text = OP1;
radioButton11.Text = OP2;
radioButton10.Text = OP3;
radioButton9.Text = OP4;
}
private void listView1_MouseClick(object sender, MouseEventArgs e)
{
if (randomQsn.GetLength(0) >= 0)
{
if (listView1.SelectedItems.Count > 0)
{
//here how should i get That particular Question so that i can display it
//something like this ? //Convert.ToInt16(listView1.SelectedItems[0].SubItems[0].Text)
DisplayQuestion(question);
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
tik++;
if (tik == 60)
{
label1.Text = (Convert.ToInt16(label1.Text) - 1).ToString();
tik = 0;
}
}
}
Thanks for any help in advance
The following is what you are looking for. You must grab the text of the list view item and use that as the index of the question.
if (listView1.SelectedItems.Count > 0)
{
var q = Convert.ToInt16(listView1.SelectedItems[0].Text);
var selectedQuestion = questions[q - 1];
DisplayQuestion(selectedQuestion);
}
In order for this to work, modify your constructor to the following:
private List<Question> questions;
public partial class GroupExmStart : Form
{
string[] randomQsn = new string[totQsn + 1]; //totQsn is the total number of question for e.g.10
public GroupExmStart(string GroupName, string DurationID)
{
InitializeComponent();
this.GrpID=GroupName;
TopiID=db.GetTopicIDForGroup(GrpID);
string[] conf = db.GetConfiguration(Convert.ToInt16(DurationID)).Split('|');
Question qsn = new Question();
/// THIS IS MODIFIED //
questions = qsn.Foo(TopiID, conf);
int z = Quiz(questions);
totQsn = Convert.ToInt16(conf[0]);
for (int kk = 1; kk <= totQsn; kk++)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = kk.ToString();
listView1.Items.Add(lvi);
}
randomQsn = new string[totQsn + 1];
timer1.Interval = 1000; //1000ms = 1sec
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
}

Loop all textbox and collect values in c# asp.net

I'm trying to get a list of strings from the database.
For each string in the list i want to add a label & textbox to the page.
On button submit I want to collect the textbox value as well as the corresponding label value then save it to the database.
I need help retrieving the values from the textboxes.
What I have so far:
Panel1 is on the aspx page
protected List<string> items = MyClass.GetItems();
protected void Page_Load(object sender, EventArgs e)
{
GenerateItemsTable();
}
private void GenerateItemsTable()
{
Table table = new Table();
table.ID = "Table1";
//PlaceHolder1.Controls.Add(table);
Panel1.Controls.Add(table);
foreach (var x in items)
{
TableRow row = new TableRow();
for (int y = 0; y < 1; y++)
{
TableCell labelCell = new TableCell();
labelCell.Controls.Add(CreateLabel(x));
labelCell.CssClass = "tdLabel";
row.Cells.Add(labelCell);
TableCell txbCell = new TableCell();
txbCell.Controls.Add(CreateRadNumericTextBox(x));
txbCell.Width = 30;
row.Cells.Add(txbCell);
TableCell dataTypeCell = new TableCell();
dataTypeCell.Text = "<span style='font-size: 10px; color: #777'>(student count)</span>";
dataTypeCell.Width = 100;
row.Cells.Add(dataTypeCell);
TableCell fourthCell = new TableCell();
if (x == items[items.Count - 1])
{
RadButton rb = new RadButton();
rb.ID = "submit";
rb.Text = "Submit Guidance";
rb.Skin = "Forest";
rb.Click += new EventHandler(submit_Click);
rb.AutoPostBack = true;
fourthCell.Controls.Add(rb);
row.Cells.Add(fourthCell);
}
else
{
row.Cells.Add(fourthCell);
}
}
table.Rows.Add(row);
}
}
private RadNumericTextBox CreateRadNumericTextBox(string x)
{
RadNumericTextBox rntb = new RadNumericTextBox();
rntb.ID = x;
rntb.Width = 40;
return rntb;
}
private Label CreateLabel(string x)
{
Label l = new Label();
l.ID = "label_" + x;
l.Text = "<label>" + x + "</label>";
return l;
}
protected void submit_Click(object sender, EventArgs e)
{
foreach (Control x in FindControl("Panel1").FindControl("Table1").Controls)
{
if (x is RadNumericTextBox)
{
//how to get the data??????/
}
}
}
(thanks to those that actually read the whole post)
-----------------updated solution--------------------------------------------
I decided to change it and store the list from the db at page_load. With the list stored i loop through the list and use FindControl() to access the textboxes. Something like this..
//a couple containers
protected class ItemVal
{
public int Value { get; set; }
public string Name { get; set; }
}
protected List<ItemVal> items = new List<ItemVal>();
//get the list from that database
protected void GetItems()
{
foreach (var x in MyClass.GetItems())
{
ItemVal i = new ItemVal();
i.Name = x;
items.Add(i);
}
}
//submit
protected void submit_Click(object sender, EventArgs e)
{
foreach (var x in items)
{
RadNumericTextBox rntb = FindControl(x.Name) as RadNumericTextBox;
x.Value = (int)rntb.Value;
}
}
You need to cast x to a RadNumericTextBox and then pull out the property values you want, like this:
RadNumericTextBox theRadNumericTextBox = x as RadNumericTextBox;
string val = theRadNumericTextBox.Text;
Then for the other controls you want, you will need to put if conditions for their types, like this:
if (x is Label)
{
Label theLabel = x as Label;
string valLabel = theLabel.Text;
}
Here is the full code for the method:
protected void submit_Click(object sender, EventArgs e)
{
foreach (Control x in FindControl("Panel1").FindControl("Table1").Controls)
{
Label theLabel;
RadNumericTextBox theRadNumericTextBox;
if (x is RadNumericTextBox)
{
RadNumericTextBox theRadNumericTextBox = x as RadNumericTextBox;
string val = theRadNumericTextBox.Text;
}
if (x is Label)
{
Label theLabel = x as Label;
string valLabel = theLabel.Text;
}
// Either store up in a list or save to the database on each loop; it is recommended to store a list and send all the changes at once for a database save, but that is your choice
}
}

move forwad and backword in listview (window explorer of computer) using stack

i have the code in which i m displaying directories and files from the computer.i can open them by using folerbrowser. so far so good but now i want to add backward and forward button so that i can see the previous folder or file selected and go fwd to.
public partial class ListView : Form
{
public ListView()
{
InitializeComponent();
comboBox1.SelectedIndex = 2;
}
private void PopulateListView()
{
listView1.Clear();
//headers listview
listView1.Columns.Add("File Name", 200);
listView1.Columns.Add("Size", 80);
listView1.Columns.Add("Last Accessed", 110);
ExtensionsHolder.Clear();
if (folderBrowser.ShowDialog() == DialogResult.OK)
{
//int thefile = 0;
string[] dirData = new string[3];
string[] filData = new string[3];
string[] files = Directory.GetFiles(folderBrowser.SelectedPath);
var folders = Directory.GetDirectories(folderBrowser.SelectedPath)
.Where(d => !new DirectoryInfo(d).Attributes.HasFlag(FileAttributes.System | FileAttributes.Hidden));
try
{
//THIS IS THE ITERATION TO GET SUBDIRECTORIES
foreach (string dir in folders)
{
//string name = Path.g;
dirData[0] = dir.ToString();
dirData[1] = dir.Length.ToString();
dirData[2] = File.GetLastAccessTime(dir).ToString();
ListViewItem lv = new ListViewItem(dirData, imageList1.Images.Count);
lv.Tag = dir;
imageList1.Images.Add(IconExtractor.Form1.GetFolderIcon(IconExtractor.IconSize.Small, IconExtractor.FolderType.Closed));
listView1.SmallImageList = imageList1;
listView1.Items.Add(lv);
}
//THIS IS ITERATION FOR FILES OF THE DIRECTORY
foreach (string file in files)
{
FileInfo finfo = new FileInfo(file);
FileAttributes fatr = finfo.Attributes;
string name = Path.GetFileNameWithoutExtension(file);
filData[0] = name;
filData[1] = finfo.Length.ToString();
filData[2] = File.GetLastAccessTime(file).ToString();
ListViewItem lv = new ListViewItem(filData, imageList1.Images.Count - 1);
lv.Tag = file;
string extension = Path.GetExtension(file);
if (!extension.Equals("") && !ExtensionsHolder.Contains(extension))
{
ExtensionsHolder.Add(extension);
imageList1.Images.Add(BlackFox.Win32.Icons.IconFromExtensionShell(extension, BlackFox.Win32.Icons.SystemIconSize.Small));
}
listView1.SmallImageList = imageList1;
listView1.Items.Add(lv);
}
}
catch (UnauthorizedAccessException)
{
listView1.Items.Add("Access denied");
}
}
}
List<string> ExtensionsHolder = new List<string>();
private void textBox1_TextChanged(object sender, EventArgs e)
{
string chattextbox=textBox1.Text;
}
private void button1_Click(object sender, EventArgs e)
{
PopulateListView();
textBox1.Text = folderBrowser.SelectedPath;
}
private void listView1_ItemActivate(object sender, EventArgs e)
{
try
{
string sPath = listView1.FocusedItem.Tag.ToString();
Process.Start(sPath);
}
catch(Exception Exc) { MessageBox.Show(Exc.ToString()); }
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if(comboBox1.SelectedIndex == 0)
listView1.View = View.LargeIcon;
if(comboBox1.SelectedIndex==1)
listView1.View = View.SmallIcon;
if(comboBox1.SelectedIndex==2)
listView1.View = View.Details;
if (comboBox1.SelectedIndex == 3)
listView1.View = View.List;
else if (comboBox1.SelectedIndex == 5)
listView1.View = View.Tile;
}
private void Farward_Click(object sender, EventArgs e)
{
//Stack fpath = new Stack();
Stack<string> itemindex = new Stack<string>();
itemindex.Push(listView1.SelectedIndices.ToString());
itemindex.Push("two");
itemindex.Push("three");
//itemindex.Push("four");
//itemindex.Push("five");
// A stack can be enumerated without disturbing its contents.
foreach (string number in itemindex)
{
Console.WriteLine(number);
}
Console.WriteLine("\nPopping '{0}'", itemindex.Pop());
Console.WriteLine("Peek at next item to destack: {0}",
itemindex.Peek());
Console.WriteLine("Popping '{0}'", itemindex.Pop());
}
private void Back_Click(object sender, EventArgs e)
{
int i = 0;
for (i = 0; i < listView1.Items.Count; i++)
{
if (i != 0)
{
listView1.Items[i - 1].SubItems[1].Text = "Selected";
// txtPath.Text = listView1.Items[i - 1].Text;
}
}
}
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (listView1.SelectedIndices.Count > 0)
MessageBox.Show("selected index"+ listView1.SelectedIndices[0]);
else
MessageBox.Show("No item selected");
}
}
}
Forward . . .
private void Farward_Click(object sender, EventArgs e)
{
//Stack fpath = new Stack();
Stack<string> itemindex = new Stack<string>();
itemindex.Push(listView1.SelectedIndices.ToString());
itemindex.Push("two");
itemindex.Push("three");
//itemindex.Push("four");
//itemindex.Push("five");
// A stack can be enumerated without disturbing its contents.
foreach (string number in itemindex)
{
Console.WriteLine(number);
}
Console.WriteLine("\nPopping '{0}'", itemindex.Pop());
Console.WriteLine("Peek at next item to destack: {0}",
itemindex.Peek());
Console.WriteLine("Popping '{0}'", itemindex.Pop());
}
Backward . . .
private void Back_Click(object sender, EventArgs e)
{
int i = 0;
for (i = 0; i < listView1.Items.Count; i++)
{
if (i != 0)
{
listView1.Items[i - 1].SubItems[1].Text = "Selected";
// txtPath.Text = listView1.Items[i - 1].Text;
}
}
}
It's kind of hard to do this because your code contains a lot of unecessary UI stuff. Anyway this is how I did it . . .
Let lvItems be our ListView, and allow A B C D be the elements in our ListView. We select only A, C, D . . .
lvItems.SelectedIndices.Add(0);
lvItems.SelectedIndices.Add(2);
lvItems.SelectedIndices.Add(3);
So in our Next button, we define the Click event as follows . . .
Stack<string> sItms = new Stack<string>();
for (int i = 0; i < lvItems.SelectedIndices.Count; ++i)
{
int idx = lvItems.SelectedIndices[i];
string itm = lvItems.Items[idx].ToString();
sItms.Push(itm);
}
// Our set contains D, C, A
// Peek() will display D
And in our Back button, we define the Click event as follows . . .
Stack<string> sItms = new Stack<string>();
for (int i = 0; i < lvItems.SelectedIndices.Count; ++i)
{
int idx = lvItems.SelectedIndices[(lvItems.SelectedIndices.Count - 1)-i];
string itm = lvItems.Items[idx].ToString();
sItms.Push(itm);
}
// Our Set Contains A, C, D
// Peek() will display A
Is this what you're looking for? Tell me how it goes . . .

Categories

Resources