See MSDN documentation for more details: CellContentClick
EDIT: Removed code that didn't work!!!--sorry, I should have ran it first.
See MSDN documentation for more details: CellContentClick
EDIT: Removed code that didn't work!!!--sorry, I should have ran it first.
Check the value of your comboBox1.SelectedItem.ToString()
. My guess it isn't what you think: "*.doc". Have you defaulted the selection before using (eg. SelectedIndex = 0)? Also, you can just use the ComboBox.Text Property to access the selected item's text as displayed in the combobox.
That's great! If you feel your problem is resolved (does appear to be), please mark this thread as solved. Cheers!
I think you need to read up on using multi-dimensional arrays in C# so you understand what you are doing, but in both of those brackets you need numbers to access the string instead of a string[], which is what it currently resolves to.
Not to discourage you from learning how to access multi-dimensional arrays, but you should consider using a strongly typed List<> instead, if you instructor would approve.
Your unsortedarray is two dimensions, but you are comparing it as though it were only one. Look at line 31 and see how you accessing areacode, then look at your if statement at line 49--see the difference?
Try this:
public static int DeleteRecord(string bookID)
{
const string query = "DELETE FROM Books WHERE l_bookID = @l_bookID";
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(query, conn))
{
cmd.Parameters.Add(new SqlParameter("@l_bookID", SqlDbType.VarChar)).Value = bookID;
return cmd.ExecuteNonQuery();
}
}
}
Here are the changes you requested. I did not modify the code that determines the actual pct of matching because you indicated that was how you wanted it to work--so don't ask me to change that portion of your code because I want to clear this off my desk so-to-speak...
In the code that follows, you will find my changes easily, because it is practically the only code that has comments! What I did was store the SearchResults meeting your existing pct match routines (with the exception of modifying the return value of CompareString method), sort the pct match, then added them to your results in descending order (highest pct match first). I hope this solves your problem.
public SearchResult[] FindString(string Text)
{
// SearchResults keyed by matched pct...
Dictionary<decimal, SearchResult> dictResults = new Dictionary<decimal, SearchResult>();
// Create a list of match pct keys, sort...
List<decimal> sortedKeys = new List<decimal>();
List<SearchResult> result = new List<SearchResult>();
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
{
if (type.IsSubclassOf(typeof(Form)))
{
if (this.ExcludeTypes.Contains(type))
continue;
using (Form f = (Form)Activator.CreateInstance(type))
{
// Now returns mathced pct instead of bool...
decimal matchPct = CompareString(Text, f.Text);
//if (CompareString(Text, f.Text))
// Only add if matched pct made minimum criteria...
if (matchPct > 0.0M)
{
SearchResult sr = new SearchResult(type, f.Text);
sr.Images.AddRange(FindImage(f));
// Add new SearchResult to our keyed matches...
dictResults.Add(matchPct, sr);
// Add key to our sort list...
sortedKeys.Add(matchPct);
}
}
}
}
// sort the list of keys for sorted lookup...
sortedKeys.Sort();
// Add each SearchResult in order …
In your particular code example, you could eliminate the else clause and simply move the return false;
to just before the end of your method block:
private bool OpenDbConnection(SqlConnection sql_con_obj)
{
try
{
//SqlConnection.ClearPool(sql_con_obj);
//SqlConnection.ClearAllPools();
if (sql_con_obj.State == ConnectionState.Closed || sql_con_obj.State == ConnectionState.Broken)
{
sql_con_obj.ConnectionString = "Data Source=.;Initial Catalog=Practice;User ID=sa;Password=sa";
sql_con_obj.Open();
return true;
}
}
catch (Exception ex)
{
ShowMessage(ex.Message);
}
return false;
}
In structuring the method's return value this way, and should you decide to add more catch(exception) clauses, etc., you will always have a return false statement at the end of your method indication failure and not have to place additional return statements for every exception type handled, which litters up the code a little.
i think im having a search problem..i think that i should find dll
for ActiveAppearanceModel and C5 and dnAnalytics needed in source file we are talking about
but i searched finding no suitable results :(ddanbe
im afraid ur site is not working
can u check it plzthanks all
I think you need to register and install Subversion software to obtain packaged projects--it's an open-source group project. From what I could see, you can still obtain/download all of the files, including the project files, and add them to your solution. I realize that is a lot of work for just wanting to check into it...
As far as that link ddanbe gave you, there is a minor typo in the address. Just delete the last two characters from the address in your browser window and it will navigate to the site. EDIT: Silly me, here is the correct address: Concave Hull
Sure. I added an edit to the end of my post and wasn't sure if you saw it, so take another peek...
I found the question interesting, so I decided to look around the internet a little. It's an interesting topic--what are you using it for?
Anyway, I did run into this link containing what looks like some well-written shape analytics. Although I have not looked into it deep enough to determine whether the value it returns for NOT convex is reliable, which the comments indicate it is then concave, I thought it was worthy of passing along: Shapes.cs
I should point out that the code requires other libraries, but I believe it is all open source. Just search for the required namespace and include the word "library" (eg "ActiveAppearanceModel library") on the Koders.com website. In that example I gave, it will bring up a link to the ActiveAppearanceModel.cs file...click on it and it will bring up a page where the project link is located: ActiveAppearanceModel.cs, and project links to the left..., etc.
I took the bulk of this code from an MSDN example. I have used TreeView a few times, but not Active Directory objects. To use, create a form and drag a TreeView control and a DirectoryEntry component onto the form, and wire the Load event...
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 ForumSolutions
{
public partial class Form_ActiveDirectoryTreeView : Form
{
public Form_ActiveDirectoryTreeView()
{
InitializeComponent();
}
private void Form_ActiveDirectoryTreeView_Load(object sender, System.EventArgs e)
{
TreeNode users = new TreeNode("Users");
TreeNode groups = new TreeNode("Groups");
TreeNode services = new TreeNode("Services");
treeView1.Nodes.AddRange(new TreeNode[] { users, groups, services });
directoryEntry1.Path = @"WinNT://"+ Environment.MachineName;//WinNT://Domain/YourComputerName
foreach (System.DirectoryServices.DirectoryEntry child
in directoryEntry1.Children)
{
TreeNode newNode = new TreeNode(child.Name);
switch (child.SchemaClassName)
{
case "User":
users.Nodes.Add(newNode);
break;
case "Group":
groups.Nodes.Add(newNode);
break;
case "Service":
services.Nodes.Add(newNode);
break;
}
AddPathAndProperties(newNode, child);
}
}
private void AddPathAndProperties(TreeNode node,
System.DirectoryServices.DirectoryEntry entry)
{
node.Nodes.Add(new TreeNode("Path: " + entry.Path));
TreeNode propertyNode = new TreeNode("Properties");
node.Nodes.Add(propertyNode);
foreach (string propertyName in entry.Properties.PropertyNames)
{
string oneNode = propertyName + ": " +
entry.Properties[propertyName][0].ToString();
propertyNode.Nodes.Add(new TreeNode(oneNode));
}
}
}
}
If you don't mind that the thread will halt for 2 seconds, you can use Thread.Sleep(2000).
Please mark as SOLVED unless you are still having trouble.
Thanks thanks a lot for the tip. Thats what i am doing. But can someone tell me more about the software?? Will SQL Server Express be sufficient ??
Thanks a lot in advance
Regards,
Mike
Here are side-by-side comparisons you can use to determine whether your Express edition is sufficient for testing what you are developing and license compliance: http://www.microsoft.com/Sqlserver/2005/en/us/compare-features.aspx
EDIT: for VS 2008 products (doc/pdf download): http://www.microsoft.com/downloads/details.aspx?FamilyId=727BCFB0-B575-47AB-9FD8-4EE067BB3A37&displaylang=en
Begin your search in this forum, where you will find all kinds of examples. Here's a hint for your search: author = sknake
As far as your 2005 Express question, I really don't know, but I would think that you just need to use a compatible connection string...
Hmmm, this application has changed a bit since my original contribution. Having to figure out exactly what it is supposed to do is the majority of the work I would say. I have been stepping through CompareString and CompareWord methods, and I believe I have been misunderstanding what you are doing all along.
First, let me say your search code is very interesting. However, your program has little or no embedded comments explaining how the FormSearcher class is supposed to work, so I need you to verify my understanding before I continue further because I don't want to waste any more time proceeding down a falsely assumed path...
As I understand it, and you need to make sure I haven't missed anything, this is how you are determining whether the given string is enough of a match to constitute the form item being displayed:
Regarding user supplied string:
1) words to compare are whitespace delimited and must be at least 2 chars in length
1a) correction (see SPLIT comment below) : there is always only one word with whitespace removed!!!
For each word (loop) against the complete form's string:
2) each word is compared to the form's string by finding the location in the form's string where the 1st character of the word is found
3) you then remove that character from the form's string and beginning again with the 2nd character of the word
4) each found word character gets …
Thanks for your reply.............
My application is attached here and in this the percentage match code is in "FormSearcher Class " .
I just want if the entered string matches100% ,then it will be on top or if it matches 50% or more with the formText ,then maximum matched result should be at top while others below( in the decreasing order of match percentage ).Like if the one formtext matches 90% ,second 85%,third 75% and fourth 50% while other formtext do not match at all, then 90%matched result should be at top ,then 85%,then 75%,then 50%. while others which do not match at all or match less than 50% should not be displayed.All the results which matches 50% or more should display ..................
Hope you understand....
I will take a look at this today. Having no idea the exact rules constituting those percentages you mention, I'll just "cross my fingers" and hope that whatever routine is already written to match an "acceptable percentage" agrees with your perception of what does and does not partially match.
OK, I think I understand now. It's a good thing I asked, because I didn't realize you expected "eval 2/3" to match "evaluate 2/3". Anyway, I know either sknake or Ryshad provided you code to match a percentage of the text. Tell me where that is so I can incorporate into the rebuilding of the list.
One last question, if I understood your last response, you now want every list item that does NOT match to be removed from your list instead of just moving the matching items to the top?
thanks , I Upload the file in this Link
When I want to Load App. , I want to insert a Suitable Value to the Rows of Column1 .
I played around with this a little bit and it has taken me a little time to figure out some things, but I think understand what you are trying to do now. Unfortunately, I have some other errands to attend to in a moment, but here are some tips for whoever endeavors...
No, I want to show the matches, no matter the user types lower case or upper case letters................
I want two things basically, that closest match should display on top and others are below
And
if user enter any number of spaces between characters and numbers in the string , So still in that case it should display the result, It should just consider the entered letters(Any type of Characters), not spaces. It should remove the spaces as getString() function does.
Kindly help me in this................
So, these should all match (and note case diff for P(X)):
Evaluate 2 / 3
evaluate 2/3
evaluate2/3
P(X) = x
P(x)=x
p(X)=X
but, these should not match:
eval 2/3
eval2/3
Is that correct?
hi DdoubleD
Here is my application..........
Kindly help me in this.................
I'm running your app. You removed the code I gave you, modified existing code, but now I'm at a point where I think I know where to make changes to fix this "once and for all".
I have a question: if the user types "eval" instead of "Eval", it will not find any matches--is that how you want it to work, or should that be changed too?
So does a hundred views but no comments mean I should elaborate on my code more or show more? Maybe I left some key parts out? I'm kinda new at this and didn't want to give too much overhead that was unnecessary since the code is starting to grow. Or does it mean that the code should be working correctly? Even just a quick "What the hell are you doing?" will help me try to clear up the confusion. I'm stuck here and everything I do seems to print the same empty panel.
LOL--I like your attitude.;) There are people in her more graphic oriented than I am, but if they don't jump in by the time I revisit tomorrow, I will dive in... If in the meantime, you come up with a small breakthrough and narrowed down issue related, do post that update..
Cheers!
EDIT: There are people in here from all over the world in different time zones, so it probably won't be much longer before someone jumps in... I'm about to go to bed myself.
Thanks for your reply Sknake, Well i m using same code which u given to me. But along with that for bringing the result on the top i m using following code:
private void DisplayResults() { textBoxCurrentPage.Text = curPage.ToString(); int recStart = 0 + (RECORDS_PER_PAGE * (curPage - 1)); int recEnd = recStart + RECORDS_PER_PAGE; listView1.BeginUpdate(); listView1.Items.Clear(); if (currentSearchResults != null) { for (int i1 = recStart; i1 < recEnd; i1++) { if (currentSearchResults.Length > i1) { ListViewItem lvi = listView1.Items.Add(currentSearchResults[i1].FormType.Name); lvi.SubItems.Add(currentSearchResults[i1].Caption); lvi.Tag = currentSearchResults[i1]; } else break; } // reorder matching search item to be at top ReorderItemToTop(textBox1.Text); } listView1.EndUpdate(); buttonNext.Enabled = (curPage < maxPage); buttonPrev.Enabled = (curPage > 1); } void ReorderItemToTop(string name) { // sort items so our FindItemWithText finds first closest match index... // this will put them in the best order based on ascending... // if there is an exact match to name, it will be found first in code below... listView1.Sort(); // Locate item beginning with name's text... ListViewItem item = listView1.FindItemWithText(name, true, 0, true); // if found and more than one item, begin moving them up the list.... // If an exact match was found, it will be put at the top... if (item != null && listView1.Items.Count > 1) { // begin moving matching items up... int index = 0; // this is the top where we will put the first/best matching item do { // move item up to next top position... item.Remove(); listView1.Items.Insert(index, item); // find next item beginning at …
Here is a crude example I built from that link I gave:
public partial class Form_DataGrid : Form
{
DataTable dt;
DataView dv;
CurrencyManager CM;
public Form_DataGrid()
{
InitializeComponent();
}
private void Form_DataGrid_Load(object sender, EventArgs e)
{
dt = BuildDynamicTableArrayExample();
dv = new DataView(dt);
dataGrid1.DataSource = dv;
dv.Sort = "FieldName1"; // sort field required for search (Find)...
// Initialize CurrencyManager to hold an instance of the form's CurrencyManager.
// Needed to manipulate the row pointer...
CM = (CurrencyManager)dataGrid1.BindingContext[dv];
}
private void button1_Click(object sender, EventArgs e)
{
int row = dv.Find(textBox1.Text); // find the text...
if (row >= 0)
{
CM.Position = row; // position the row pointer...
dataGrid1.Select(row); // if wanting to highlight the row too...
}
}
public static DataTable BuildDynamicTableArrayExample()
{
// Create new DataTable object...
DataTable dt = new DataTable();
dt.TableName = "MyDataTable"; // Optional unless serializing datatables
// Add some columns to the table...
dt.Columns.Add(new DataColumn("FieldName1", typeof(string)));
dt.Columns.Add(new DataColumn("FieldName2", typeof(int)));
dt.Columns.Add(new DataColumn("FieldName3", typeof(double)));
// Optional primary key field specifier...
dt.Columns["FieldName1"].Unique = true;
// generate some rows of data...
for (int r = 0; r < 10; r++)
{
// create a row object of table object's type defined above
DataRow dr = dt.NewRow();
// Set each column value in the row...
dr["FieldName1"] = "data " + r;
dr["FieldName2"] = r;
dr["FieldName3"] = (double)r;
// add the row to the table
dt.Rows.Add(dr);
}
return dt;
}
}
EDIT--NOTE: I do not UnSelect(int rowID)
any rows and although it will move the row pointer every time, it …
I believe you can convert the image using the Image.Save
method. So, instead of using FileStream:
Image img = Image.FromFile(srcFile); // load tiff
img.Save(i + ".jpeg", ImageFormat.Jpeg); // save as jpeg
I think will work, but I'm not 100% sure.
Here is an example of searching a DataGrid: How to implement a searchable DataGrid...
To select the row, of course: dataGrid1.Select(int rowId);
1) Right click on the report, select Insert=>Summary...
2) Select the field you want to sum from the "Choose the field to summarize" combobox and indicate "Sum" in the "Caculate this summary" combobox...
Hi! I am a beginer in C# and I have 2 forms in a project. The first one contains a dataGridview with 3 columns: nr,date and obs and a button. when i select a row and click on a button i want to copy the current nr,date and obs in some textboxes from the second form. how do i refer to thouse from the second form? Can anyone tell me, please? thanks.
One way you could do it is to copy/paste from the Clipboard
.
Another way is to directly pass that data to the second form.
What is your usage preference?
It wasn't clear to me whether your question was for obtaining the state, as you have already been directed, or you are wanting to set the state, which I will throw out some additional direction below.
// ListBox method to select an item...
public void SetSelected(int index, bool value);
public ListBox.SelectedObjectCollection SelectedItems { get; } // to see all items selected...
// and, to capture when the selection is changing:
public event EventHandler SelectedIndexChanged;
// RadioButton method to get/set state:
public bool Checked { get; set; }
// and, to capture when the state has been changed:
public event EventHandler CheckedChanged;
// ComboBox methods to select item:
public override int SelectedIndex { get; set; }
public object SelectedItem { get; set; }
// and, to capture when the selection has changed:
public event EventHandler SelectedIndexChanged;
If you search on these, you should be able to find all the example code you need to see/understand how these are implemented in a form.
Cheers!
No actually problem is, let i have a form text "evaluate 2/3+5/6", So when user write this string in textbox like this "evaluate 2/3 + 5/6."
So here the difference between both is just spacing difference after 2/3 and before 5/6.
So i want if user enters more spaces or less spaces may be(sometime like this"evaluate2/3+5/6.(there is no space in this string)" So he still get the closest result on top, but the code you gave to me is not doing this. I mean if i write "evaluate 2/3 + 5/6."
So it is not given at top..................
I hope my problem is clear to you........
Kindly help me in this...................
So, for this example you gave, all you need to do is strip those spaces before comparing to list and reordering list:
string s = "evaluate 2/3 + 5/6"; // original text entered by user...
string sCmpr = s.Substring(0, 9); // retain beginning of string...
sCmpr += s.Substring(9).Replace(" ", string.Empty); // remove spaces in formula...
// sCmpr will now look like: "evaluate 2/3+5/6"
then use sCmpr
in the call to the void ReorderItemToTop(string name)
reordering method I already gave you...
Hi DdoubleD ,
The code which you have given me is not working properly........
According to your code if the string entered in the textbox exactly matches with the form text
only then it shows that result on top otherwise not.....
Well In my application i match the textbox string with each form text and calculate how much percent it
matches.So is it possible that After finding the percents match for each string collect all the percentages in an
array and then sort them in decreasing order.
In this way the form which matches by maximum perecntage will be on top in all cases.
Can you please tell me how to implement this..........
If I remember correctly, the snippet I gave you reorders the list based on matching the beginning of the text. I believe that I performed a sort on the list first, so it should have began moving up matches to the top beginning with:
1) any exact match it found,
2) any partial string matches at the beginning text.
Is it not doing this?
Sent you sent me a PM, I took a quick search: http://en.wikipedia.org/wiki/Law_of_cosines
I was then going to suggest that ddanbe is your man for this question, but I see he is already on top of it.;)
Maybe my answer is a little too obvious, but if you place the mdb on a machine having a folder that is shared on the LAN, then you only need to have your application browse to the location of the mdb and connect to it there.
LOL, I guess there are row headers... I just did the following to test using it and it worked:
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
dataGridView1.Rows[e.RowIndex].HeaderCell.Value = "Obj " + e.RowIndex;
}
So, how are you doing it?
What is a row header? Aren't the values you are showing as being incorrect really just incorrect cell values in the first column without a column heading?
If you have not already, take a look at this thread, which quite a bit of work went into related to your question: http://www.daniweb.com/forums/thread226540.html
Then, if you have tried implementing this and cannot get it to work the way you want, post the relevant code with question (project too to be sure).
Ryshad, that code looks good to me, but for some reason when I execute it (have only tried with one PictureBox added in the panel) the
Remove(pic2remove)
method in thepicture_click()
event doesn't seem to remove the control from the panel. I don't see why this wouldn't work and it relates to a similar post I made where you provided input as well... Any thoughts as to why this is?
My apologies sir... That code works fine. I had my form and panel sized so small I didn't notice it was filling that location with next picture... :$ One of those moments for me I suppose....
Ryshad, that code looks good to me, but for some reason when I execute it (have only tried with one PictureBox added in the panel) the Remove(pic2remove)
method in the picture_click()
event doesn't seem to remove the control from the panel. I don't see why this wouldn't work and it relates to a similar post I made where you provided input as well... Any thoughts as to why this is?
Heres some code demonstrating how to name the control at creation and adding an event handler to its Click() event. I have used the click event to delete the control:
namespace WindowsApplication3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { for (int i = 0; i < 10; i++) { PictureBox pb = new PictureBox(); pb.Image = Properties.Resources.pic1; pb.Name = "pic" + i.ToString(); pb.Click += new EventHandler(picture_click); flowLayoutPanel1.Controls.Add(pb); } } void picture_click(object sender, EventArgs e) { PictureBox pic2remove = (PictureBox)sender; flowLayoutPanel1.Controls.Remove(pic2remove); } } }
Can explain better what it is you are doing?
Please mark this thread as solved and create a new thread with question about matching string expressions.
Cheers!
Here is some code to show you what you asked:
// 2nd param false if not searching child controls of control...
Control[] ctrls = flowLayoutPanel1.Controls.Find("searchkey", false);
// Note: only one can be selected (made active), so if Find returns more than one,
// the last one in array will be the selected control using this loop...
foreach (Control c in ctrls)
c.Select();
// if only one control returned (exact match), make it active...
if (ctrls.Length > 0)
{
ctrls[0].Select();
// to remove this control...
flowLayoutPanel1.Controls.Remove(ctrls[0]);
}
Here you go....
private void DisplayResults()
{
textBoxCurrentPage.Text = curPage.ToString();
int recStart = 0 + (RECORDS_PER_PAGE * (curPage - 1));
int recEnd = recStart + RECORDS_PER_PAGE;
listView1.BeginUpdate();
listView1.Items.Clear();
if (currentSearchResults != null)
{
for (int i1 = recStart; i1 < recEnd; i1++)
{
if (currentSearchResults.Length > i1)
{
ListViewItem lvi = listView1.Items.Add(currentSearchResults[i1].FormType.Name);
lvi.SubItems.Add(currentSearchResults[i1].Caption);
lvi.Tag = currentSearchResults[i1];
}
else
break;
}
// reorder matching search item to be at top
ReorderItemToTop(textBox1.Text);
}
listView1.EndUpdate();
buttonNext.Enabled = (curPage < maxPage);
buttonPrev.Enabled = (curPage > 1);
}
void ReorderItemToTop(string name)
{
// sort items so our FindItemWithText finds first closest match index...
// this will put them in the best order based on ascending...
// if there is an exact match to name, it will be found first in code below...
listView1.Sort();
// Locate item beginning with name's text...
ListViewItem item = listView1.FindItemWithText(name, true, 0, true);
// if found and more than one item, begin moving them up the list....
// If an exact match was found, it will be put at the top...
if (item != null && listView1.Items.Count > 1)
{
// begin moving matching items up...
int index = 0; // this is the top where we will put the first/best matching item
do
{
// move item up to next top position...
item.Remove();
listView1.Items.Insert(index, item);
// find next item beginning at index + 1 (skip one we just moved)...
index++;
item = listView1.FindItemWithText(name, true, index, true);
} while (item != null); // until no more matches...
}
}
or perhaps this?:
public void MakeItemTopVisible(string name)
{
// Locate item beginning with name's text...
ListViewItem item = listView1.FindItemWithText(name, false, 0, true);
// make item first (top) item viewable in the list...
listView1.TopItem = item;
}
OK, is this what you want? Still not tested, but you can look at comments and logic to determine if I have understood your request:
void ReorderItemToTop(string name)
{
// sort items so our FindItemWithText finds first closest match index...
// this will put them in the best order based on ascending...
// if there is an exact match to name, it will be found first in code below...
listView1.Sort();
// Locate item beginning with name's text...
ListViewItem item = listView1.FindItemWithText(name, false, 0, true);
// if found and more than one item, begin moving them up the list....
// If an exact match was found, it will be put at the top...
if (item != null && listView1.Items.Count > 1)
{
// begin moving matching items up...
int index = 0; // this is the top where we will put the first/best matching item
do
{
// move item up to next top position...
item.Remove();
listView1.Items.Insert(index, item);
// find next item beginning at index + 1 (skip one we just moved)...
index++;
item = listView1.FindItemWithText(name, false, index, true);
} while (item != null); // until no more matches...
}
}
Not sure if this is what you are looking for and I didn't test this, but it should work OK:
void ReorderItemToTop(string name)
{
// Locate item beginning with name's text...
ListViewItem item = listView1.FindItemWithText(name);
// If exact match, move it to the top of the List...
if (item != null && name == item.Text)
{
item.Remove(); // remove from current location...
listView1.Items.Insert(0, item); // insert at top...
}
}
You need to check that index because maybe there is no student selected or something.
if (students.SelectedItem < 0)
MessageBox.Show("No student selected...");
else if (students.SelectedItem >= studentList.Count)
MessageBox.Show("Programmer Error: List out of Sync with ListBox!");
I have dinner plans so I have to leave now... Good luck and look at all of those comments I made for you showing how to check index to make sure it is valid...
Here is what you had before:
private void deleteStudent_Click_1(object sender, EventArgs e)
{
if (!DeleteStudent(students.SelectedIndex)) //check if student is selected from list.
MessageBox.Show("Error deleting student..."); //throw message box saying that a student isn't selected.
}
private void deleteStudent_Click_1(object sender, EventArgs e) { if (!DeleteStudent(studentsList.SelectedIndex)) //check if student is selected from list. MessageBox.Show("Error deleting student..."); //throw message box saying that a student isn't selected. }
Why did you change this method? It was more correct the way you had it before. This won't even compile because "studentList" does not have a SelectedIndex
property.