I'm just trying to search strings in my ListBox and I thought I had it pretty much down pat until I came to this issue:
An unhandled exception of type 'System.NotImplementedException' occurred in **.exe
Additional information: The method or operation is not implemented.
Here is my piece of code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace *****
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
add();
}
private void button2_Click(object sender, EventArgs e)
{
search();
}
public void search()
{
if (textBox2.Text == string.Empty)
{
MessageBox.Show("Must enter value");
}
else
{
string toFind = textBox2.Text;
if (toFind != string.Empty)
{
int search = listBox1.FindString(toFind);
if (search != -1)
{
listBox1.SetSelected(search, true);
}
else
{
MessageBox.Show("Could not find "+toFind);
}
}
}
}
public void add()
{
if (textBox1.Text == string.Empty)
{
MessageBox.Show("Must enter value");
}
else
{
listBox1.Items.Add(textBox1.Text);
}
textBox1.Clear();
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter)
{
add();
}
}
private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
search();
}
}
}
}
Search your whole project for following:
throw new NotImplementedException();
and do comment it ;)
Related
I have an error that I cannot figure out.
I have just put some text here, please guide.
Here's the error:
Type or namespace definition, or end-of-file expected
Invalid token 'else' in class record, struct, or interface member declaration
Here's the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace IMS
{
public partial class Login : BaseForm
{
public Login()
{
InitializeComponent();
}
private void Usernametxt_TextChanged(object sender, EventArgs e)
{
if (Usernametxt.Text=="") {usernameError.Visible = true;}else{ usernameError.Visible = false; }
}
private void Passtxt_TextChanged(object sender, EventArgs e)
{
if (Passtxt.Text == ""){passError.Visible = true;}else { passError.Visible = false;}
}
private void label3_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (Usernametxt.Text == "" && Passtxt.Text == "")
{
if (Usernametxt.Text == "") {usernameError.Visible = true; }else{usernameError.Visible = false;}
if (Passtxt.Text == ""){passError.Visible = true;}else{ passError.Visible = false;}
}
else
{
}
}
}
}
I want to access the latest checkstates and the latest set date value using a function called GetProfileFilter. Now my problem is I'm not able to fetch the latest values when either the checkbox.Checkstate is changed or the datetimepicker is changed.I'm setting the values based on whether the checkboxes are set and I intend to use the IBitWise value elsewhere.Note that at form load all the checkboxes are checked.In the form class I have nothing more than a few variable and the event handlers for buttons and checkboxes and date time pickers.Open to all suggestions!!
class Profile{
public bool GetProfileFilter()
{
if (frmInactive.btnApplyWasClicked == true || frmInactive.btnCancelWasClicked == false)
{
frmInactive.ShowDialog();
MessageBox.Show("Here");
if (frmInactive.chkCancel.Checked == true)
{
MessageBox.Show("Cancel");
IBitWise += Canceled;
}
if (frmInactive.chkDiscon.Checked == true)
{
MessageBox.Show("Discon");
IBitWise += Discontinued;
}
if (frmInactive.chkVoidwoRes.Checked == true)
{
MessageBox.Show("Voidedwo");
IBitWise += VoidedWoutRes;
}
if (frmInactive.chkVoidwRes.Checked == true)
{
MessageBox.Show("Voidedw");
IBitWise += VoidedWRes;
}
MessageBox.Show("Ibit value:" + IBitWise);
return true;
}
else
{
return false;
}
}
}
public partial class FilterView : Form
{
Utilities Utilities = new Utilities();
//FilterView filterView = new FilterView();
public FilterView()
{
InitializeComponent();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
}
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
}
private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
}
private void checkBox5_CheckedChanged(object sender, EventArgs e)
{
}
private void rsetbtn_Click(object sender, EventArgs e)
{
}
private void aplybtn_Click(object sender, EventArgs e)
{
callonload();
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
}
private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
{
}
Here is sample code with checkbox made public
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Profile profile = new Profile(this);
profile.GetProfileFilter();
}
}
class Profile
{
Form1 form1;
public Profile(Form1 form1)
{
this.form1 = form1;
}
public bool GetProfileFilter()
{
form1.checkBox1.Checked = true;
return true;
}
}
}
I wish to know how to store a VALUE to an item in a listbox. I'm currently working out a worksheet for my studies, and I've been wondering how to do this. Basically I need to store values to the Food (such as broccoli, bread. For example: Broccoli has a value of 20 calories).
The user must not see the value, only the program can store it.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MCAST_Calorie_Counter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
lbAvailable.Items.Clear();
if (comboBox1.Text == "Vegetables")
{
lbAvailable.Items.Add("Broccoli");
lbAvailable.Items.Add("Carrots");
lbAvailable.Items.Add("Lettuce");
lbAvailable.Items.Add("Onions");
lbAvailable.Items.Add("Potatoes");
}
if (comboBox1.Text == "Meat")
{
lbAvailable.Items.Add("Chicken");
lbAvailable.Items.Add("Veal");
lbAvailable.Items.Add("Beef");
lbAvailable.Items.Add("Fish");
}
if (comboBox1.Text == "Legumes")
{
lbAvailable.Items.Add("Bread");
lbAvailable.Items.Add("Peanuts");
lbAvailable.Items.Add("Green Peas");
lbAvailable.Items.Add("Lentils");
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
ListBox.SelectedObjectCollection highlightedItems = lbAvailable.SelectedItems;
foreach (var item in highlightedItems)
{
lbChosen.Items.Add(item);
}
if (lbAvailable.SelectedItems.Count > 0)
{
lbAvailable.Items.Remove(lbAvailable.SelectedItems[0]);
}
}
private void btnRemove_Click(object sender, EventArgs e)
{
ListBox.SelectedObjectCollection highlightedItems = lbChosen.SelectedItems;
foreach (var item in highlightedItems)
{
lbAvailable.Items.Add(item);
}
if (lbChosen.SelectedItems.Count > 0)
{
lbChosen.Items.Remove(lbChosen.SelectedItems[0]);
}
}
private void btnClear_Click(object sender, EventArgs e)
{
lbAvailable.Items.Clear();
lbChosen.Items.Clear();
if (comboBox1.Text == "Vegetables")
{
lbAvailable.Items.Add("Broccoli");
lbAvailable.Items.Add("Carrots");
lbAvailable.Items.Add("Lettuce");
lbAvailable.Items.Add("Onions");
lbAvailable.Items.Add("Potatoes");
}
if (comboBox1.Text == "Meat")
{
lbAvailable.Items.Add("Chicken");
lbAvailable.Items.Add("Veal");
lbAvailable.Items.Add("Beef");
lbAvailable.Items.Add("Fish");
}
if (comboBox1.Text == "Legumes")
{
lbAvailable.Items.Add("Bread");
lbAvailable.Items.Add("Peanuts");
lbAvailable.Items.Add("Green Peas");
lbAvailable.Items.Add("Lentils");
}
}
}
}
Thanks alot for your help!
You can always add custom objects that support ToString() to the ListBox.Items collection:
struct Record
{
int value;
string label;
public override string ToString()
{
return label;
}
}
Adding a custom object:
Record record = new Record();
record.value = 1;
record.label = "This text will appear in the ListBox";
listBox.Items.Add(record);
Retrieving it:
Record selectedRecord = (Record)listBox.SelectedItem;
Console.WriteLine(selectedRecord.value); // => 1
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace Temporizador
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
/*if (escolherHoraTxt.InvokeRequired == true)
escolherHoraTxt.Invoke((MethodInvoker)delegate { escolherHoraTxt.Text = "Invoke was needed"; });*/
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void escolherFicheiroBtn_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.ShowDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
string fileName;
fileName = dlg.FileName;
link.Text = fileName;
//MessageBox.Show(fileName);
}
}
private void escolherHoraTxt_MouseClick(object sender, EventArgs e)
{
if (escolherHoraTxt.Text == "--:--:--")
escolherHoraTxt.Text = " ";
}
private void escolherHoraTxt_TextChanged(object sender, EventArgs e)
{
if (escolherHoraTxt.Text == "--:--:--")
escolherHoraTxt.Text = " ";
}
private void gravarBtn_Click(object sender, EventArgs e)
{
}
private void gravarBtn_Click_1(object sender, EventArgs e)
{
String s = escolherHoraTxt.Text;
Horas hora = new Horas();
hora.IsValidTime(s);
hora.compareTime(s);
}
}
}
Horas.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace Temporizador
{
class Horas
{
private String m_timeNow;
public String timeNow
{
get
{
return m_timeNow;
}
set
{
m_timeNow = value;
}
}
public Horas()
{
}
public string getCurrentTime()
{
m_timeNow=DateTime.Now.ToString("HH:mm:ss");
return m_timeNow;
}
public void IsValidTime(String theTime)
{
string[] timeArray = theTime.Split(new[] { ":" }, StringSplitOptions.None);
try{
Convert.ToDateTime(theTime);
}
catch (FormatException e)
{
MessageBox.Show(e.Message);
}
}
public void compareTime(String theTime)
{
string currentTime=getCurrentTime();
if (currentTime == theTime)
MessageBox.Show("SIM");
else
MessageBox.Show("NAO");
}
}
}
/I´m trying to make an application that it is always running and that will close and then open a file in a certain hour choosen by the user. I intend to use something like while(1){...} but I don´t know in what part of the program should I put this. Could someone help me please?/
hey i wrote below code to send my datagridview value seleted row to another form but i got this error my event is double content click and i dont know why this happened
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
using System.Windows.Forms;
namespace WindowsFormsApplication12
{
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
private void Form5_Load(object sender, EventArgs e)
{
tblClassTableAdapter.Fill(dataSet1.tblClass);
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
this.tblClassTableAdapter.FillBy1(this.dataSet1.tblClass, textBox1.Text);
}
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
new Form6(int.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString())).Show();
}
}
and my form 6
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication12
{
public partial class Form6 : Form
{
int classid;
private string p;
public Form6(int myid)
{
classid = myid;
InitializeComponent();
}
public Form6(string p)
{
// TODO: Complete member initialization
this.p = p;
}
public void Form6_Load(object sender, EventArgs e)
{
textBox1.Text = classid.ToString();
}
public DataGridViewRow dataGridViewRow { get; set; }
}
}
thank you guys for helping
DataGridViewCellEventArgs has two important args for you:
e.rowIndex, e.columnIndex which specifying in which cell you pressed.
By the way, you are trying to parse Int from cell, surround it with try/catch for case the parse fails.
try this code instead:
try {
if (e.ColumnIndex > -1 && e.RowIndex > -1)
new Form6(int.Parse(dataGridView1[e.ColumnIndex,e.RowIndex].Value.ToString())).Show();
}
catch (Exception ex) {
MessageBox.Show("Error: " + ex.Message);
}
I think it should help you, mark as answered if yes.