Let me see if I can find some old code I've written..
Mike Askew 131 Veteran Poster Featured Poster
Let me see if I can find some old code I've written..
In my experience with listboxes (they use the same fields)
You bind the datatable as the datasource of the combobox, then give the column names for the displaymember and valuemember as required.
The DisplayMember and ValueMember settings of the combo-box allow you to make the display value different to the selected one.
Can we see said XML file and higlight what causes the issues?
Could you not base the progress bar off how many files have been copied?
Max value = total file number
progress value = amount copied?
Yup exactly like the are you sure buttons, it forces a response.
try googling "custom modal forms c#"
It could probably exist but I dont see the logic behind the three buttons as there is no way apart from using a modal popup to force someone to click x or y button before proceeding. Hence the point that the button is modal.
Because with your method they can click the doStuff button without clicking either other one. The doStuff button can then not force the clicking of either of the other buttons, it is still down to the users choice unless you lock them out using a modal form.
Feel free to correct me if im wrong Deceptikon.
The adaption to Deceptikon's response here would be to make a custom form that looks like a message box proving two buttons, 1 and 10, and then use .ShowDialog()
on the customer form to display it modally, therefore forcing a response to the form before continuing.
You could then assign the form returning a yes reponse to the 1 button and a no to the 10 button creating what you require.
You may need to tweak my variable declaration to get the length right, but you were overwriting the originals passed in as well as returning them to the new array as output.
public string[] HandleString(string[] str)
{
string[] TheResults = new string[str.Length];
for (int a = 0; a <= 51; a++)
{
TheResults[a] = str[a];
TheResults[a] = TheResults[a].Replace(" Hjärter ", "");
TheResults[a] = TheResults[a].Replace(" Ruter ", "");
TheResults[a] = TheResults[a].Replace(" Spader ", "");
TheResults[a] = TheResults[a].Replace(" Klöver ", "");
}
return TheResults;
}
If myObject.HandleString(Cards);
has a return value, CardsNumber = myObject.HandleString(Cards);
will set CardsNumber to be that value.
Cards
would be modified if it is a form level variable and the method makes changes to the Cards
variable within it.
Can we see the method code and that might help find the change that you dont want.
You have two options to convert a string to an integer, convert and tryparse.
string TempString = 0;
int OutInt = Convert.ToInt32(TempString); // This will exception if not viable to convert to integer
string TempString = 0;
bool Success;
int OutInt;
Success = int.TryParse(TempString, out OutInt); // This will return true if the convert was successful and false if it wasn't but will NOT exception and is generally the better practice.
Mod, by earning the management teams respect and trust, along with other factors most likely.
Admin, can't say I know.
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Cassandra myObject = new Cassandra();
string a ="söt";
a = myObject.hejsan(a);
System.Console.WriteLine(a);
Console.ReadLine();
}
}
class Cassandra
{
public string hejsan(string value)
{
value +="Cassnadra";
return value;
}
}
}
Line 10, you need to assign a to be the output of the method, as I have done in the above code.
Nono, look at the first line of my code block, that is where the brackets go.
public string[] CreateCards()
public string[] CreateCards( string[] Cards)
{
Cards = new string[52];
for (int a = 0; a <= 51; a++)
{
if (a <= 12)
{
Cards[a] = " Hjärter " + (a+1).ToString();
}
if (a > 12 && a <= 25)
{
Cards[a] = " Ruter " + (a-12).ToString();
}
if (a > 25 && a <= 38)
{
Cards[a] = " Spader " + (a-25).ToString();
}
if (a > 38)
{
Cards[a] = " Klöver " + (a-38).ToString();
}
}
return Cards; //i get wrong here saying i need to return an array and Cards[] wont work
//because they expect a value
}
Need to add []
to the return in method declaration to make it an array.
Whats the CashAccRef declared as in the database? What type? As I assume its going to be a mismatch between what you are passing and what it expects.
Im pretty sure it will be similar to the ListView approach, using a SQL query with a variable added in passing a primary key of some sort.
So... I must not be reading the other part of the SQL Correctly. I'm not to sure what
this part means.. ={0} ?? what is this trying to reference?
Right to explain this. The following two lines of code do the same thing.
Console.WriteLine("The cat sat on" + " the " + "mat.");
Console.WriteLine(string.Format("The cat sat on {0} mat.", "the");
Basically the second line allows you to insert the values after the actual text string, so in the above case, the string "the" is added where {0} is. For longer strings with multiple entries it is simply comma-seperated values after the string like so:
Console.WriteLine("The {0} sat on the {1} and the {2} ate it.", "cat", "mat", "dog");
Obviously the strings can be replaced with any sort of variable, in your case the .Tag
property.
Basically it keeps strings cleaner that concatenating everything with +
'
Right im fast running out of ideas at the moment :D
Have you checked the SQL string at run time is correct? Ie. the .tag
is correctly being passed into the sql.
Its declared but isnt instanciated (I could be completely wrong here, and it wont make a difference) but try: DataTable cashOrderTable = new DataTable();
on line 15.
Hmm outside my knowledge on how to get the exact string, my attempts have failed so far.
cashOrderTable
is not declared as a new datatable prior to use. Im guessing that might be it? Unless that is declared and instanciated elsewhere?
And what happens when running this? It should just show a message when you select something new stating the tag and name.
Your welcome, mark the post as solved please :)
So just the title info?
Sorry the explanation confused me xD
It would be the a reference to the column holding the customerID.
and yeah I know the brain fried feeling..
Ummm.. listView1.Items[listView1.Items.Count - 1].Tag = x
That line would be added into the current for-each loop.
Ok so I achieved a similar effect using the ListView's tag property.
This is how I added some fake data, its an adaption to your code shown in post #1
edit: by which I mean the for-each loop, the table structure is identical to my above post, I continued using all that code to do this :)
foreach (DataRow row in DS.Tables["NameTable"].Rows)
{
ListViewItem temp = new ListViewItem();
temp.Text = row.ItemArray[1].ToString();
temp.Tag = row.ItemArray[0].ToString();
listView1.Items.Add(temp);
}
This hides the ID in the tag
property of the individual item on the listview.
You can then adapt my code in the ListBox post to instead look at the tag property of the selected item to view the ID and carry out the SQL.
Used this line to check the tag worked etc on ListView selected index changed
foreach (ListViewItem item in listView1.SelectedItems)
{
MessageBox.Show("Tag: " + item.Tag + " | Text: " + item.Text);
}
Hopefully that might work :)
On a seperate note - your welcome Mark :) Good ol' waiting on email replies giving me time to write this
Well thats the best blunder I've pulled off on this site... Skimread the question and never re-read it!
Gimme a while and I'll try figure it out :)
Ok sorry for this not being actual code but its quicker for me to write to the code in a descriptive process and answer questions than mess around with setting up fake datasets and then try to SQL them (been trying for the last 20 mins and failing).
To bind a listbox to a data source.
Dataset: DS
For example we have a table called CustomerTable
with two rows CustomerID
and CustomerName
, will assume we have already run the SQL to select this information and it is in the dataset DS
And a second called OrderTable
with rows OrderID
, CustomerIDFK
and ItemID
which we will be running SQL off.
Our listboxes are List1
and List2
.
To setup our first list with the customer names and their ID's as the selected value:
List1.DataSource = DS.Tables["CustomerTable"];
List1.DisplayMember = "CustomerName"; //The column name as a string
List1.ValueMember = "CustomerID";
So now in the SelectedIndexChanged
action of the listbox List1
we will run an SQL query to the second table.
string SQLToRun = string.Format("Select * From OrderTable Where CustomerIDFK = {0}", List1.SelectedValue); //The string.Format allows use of {0} and then specifying the value after the end of the string, makes it a bit tidier than cutting off the string at '=' and then concat'ing the .SelectedValue in
This would return all the rows matching the CustomerID selected in List1 (it probably wouldnt as im rusty with SQL but oh well!)
And then following the same steps as with List1
we …
Could you not store which image is selected in a Session? and then pull up the correct image on the next page using the session value?
(don't do much ASP.Net work so cant remember if this works)
@nmaillet, Didn't know you could leave the second part of the count specifier blank for any amount :)
@nesa24casa - the fix for my solution with your updated requirements using nmaillet's capturing. Also made it so it captures both <tab>
and \t
for the sake of covering all options :) simply remove |<tab>
from the regex if you dont need it covered
string inputString = "nesa\t\tpera<tab><tab><tab><tab>nn\t\t\t\t\t\tkkn";
string regexMatch = "(\t|<tab>){2,}";
string regexReplace = ",";
That works too :)!
I will try to get back to you this afternoon, work is busy.
Else I'll write up an example tomorrow :)
Sorry for the inconvienience.
See my response on here: http://www.daniweb.com/software-development/csharp/threads/432707/help-with-linking-ids-to-show-in-listview-below
It is a similar question.
Listboxes have the ability to store different values underlying to what the user sees and utilising this will make the retrieving of data alot easier.
Hi Mark,
You would need to set up the first list so that the .SelectedItem
in list box (What you can physically see) is as you state above, but the .SelectedValue
contains the actual ID value.
Then the SQL can adjust too:SELECT ID,QTY,Description,Supplier,Date,Cost,Sell from cashOrders INNER JOIN cashCustomers ON cashOrders.cashAccountRef_FKID=cashCustomers.CashAccRef WHERE cashCustomers.CashAccRef = " + listview1.SelectedValue;
Havent tested this so the SQL might not work but thats the jist of it. It basically selects all the required information from the cashOrders table based on the Id linked to the cashCustomers table where we compare that to the passed ID value from the .SelectedValue
of the listbox1.
In terms of binding the listbox to get the information working correctly, if I remember rightly, it is done by binding the listbox to the datasource and then specifying which columns are the .DisplayMember
(is visually seen) and .DataSource
.
That probably isnt explained clearly as its been about a year since I've done such xD
This might help explain it also.
string inputString = "nesa<tab><tab>pera<tab><tab><tab><tab>nn<tab><tab><tab><tab><tab><tab>kkn";
string regexMatch = "(<tab>){2,20}";
string regexReplace = "<tab>";
string outputString;
outputString = Regex.Replace(inputString, regexMatch, regexReplace);
Specifically for <tab>
Match: (<tab>){2,20}
Replace: <tab>
This will match occurances of <tab>
between 2 and 20 in a row, can adjust as needed. Works on your provided example though.
Input: nesa<tab><tab>pera<tab><tab><tab><tab>nn<tab><tab><tab><tab><tab><tab>kkn
Output: nesa<tab>pera<tab>nn<tab>kkn
Sorry, easy fix, replace the current bottom if statement with:
if (countNum != skipNum)
{
// Use static Path methods to extract only the file name from the path.
fileName = System.IO.Path.GetFileName(s);
destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(s, destFile, true);
skipNextFiles = true;
}
Code is tweaked and tested. With a skipNum of 2, I got files copied: 1, 2, 5, 6, 9, 10 of 10 files.
static void Main(string[] args)
{
string fileName;
string destFile;
string sourcePath = @"C:\Users\maskew\Documents\DaniWeb\Source";
string targetPath = @"C:\Users\maskew\Documents\DaniWeb\Destination";
// To copy all the files in one directory to another directory.
string[] files = System.IO.Directory.GetFiles(sourcePath);
// Copy the files and overwrite destination files if they already exist.
bool skipNextFiles = false;
int skipNum = 2; //as per the example, set this however you like.
int countNum = 0; //used to track how many files copied since last skipped file.
foreach (string s in files)
{
if (skipNextFiles)
{
if (countNum != skipNum)
{
countNum++;
if (countNum == skipNum)
{
countNum = 0;
skipNextFiles = false;
}
}
}
else
{
if (countNum != skipNum)
{
// Use static Path methods to extract only the file name from the path.
fileName = System.IO.Path.GetFileName(s);
destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(s, destFile, true);
countNum++;
if (countNum == skipNum)
{
countNum = 0;
skipNextFiles = true;
}
}
}
}
}
Ah shoot sorry missed that when reading the reqs, gimme a min, going to put this into visual studio and fix it.
static void Main(string[] args)
{
string fileName;
string destFile;
string sourcePath = @"E:\Source";
string targetPath = @"E:\Destination";
// To copy all the files in one directory to another directory.
string[] files = System.IO.Directory.GetFiles(sourcePath);
// Copy the files and overwrite destination files if they already exist.
int skipNum = 1; //as per the example, set this however you like.
int countNum = 0; //used to track how many files copied since last skipped file.
foreach (string s in files)
{
if (countNum != skipNum)
{
// Use static Path methods to extract only the file name from the path.
fileName = System.IO.Path.GetFileName(s);
destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(s, destFile, true);
countNum++;
}
else
{
countNum = 0;
}
}
}
Have written this in the reply without testing but its pretty simple so should work hopefully, lemme know any errors and i'll resolve.
Change the value in the dataset it is bound too, and then update the datagrid.
Datagrid paging: http://www.codeproject.com/Articles/16303/DataGrid-Paging-C-Windows-Forms
What exactly is the issue with the progress bar? Does it update? Or does it stay blank and update at the end? Please clarify
It is worth noting if you are not running a multi-threaded application the load bar will not update normally as the form will 'freeze' until the whole thread has run, ie. bar will jump from 0% to 100%.
Ah thats fine then was just double checking, it would still show up when disabled so dont worry about it.
It is worth reading the "Read before posting" post next time Q8iEnG.
B – Please Uninstall or Disable any P2P (peer-to-peer) programs on the infected computer before posting in this forum. Rather than write a long piece on the dangers of P2P, I’m just going to say this:
P2P software circumvents common-sense security measures and opens a user’s computer to a world of hurt.
Our regular volunteers' time is valuable and most are not willing to waste it on a machine that is almost certain to be reinfected in short order.
So, please remove or disable all P2P software for the duration of the cleaning process. Failure to do so may result in your thread being ignored.
and when we look through your logs..
"{1D153C11-407C-4823-B602-8C1EACFA2F3A}" = protocol=6 | dir=in | app=c:\program files (x86)\utorrent\utorrent.exe |
"{37F69D7D-74C5-46E5-8A50-8558958E15B2}" = protocol=17 | dir=in | app=c:\program files (x86)\utorrent\utorrent.exe |
That is also most likely the origination of your problem right there :)
That's also fine, mine was written the way it is as you said the HREF was dynamic and so mine covered all bases.
Don't for get to mark the thread as solved if your issue is fixed.
That should do it for you. The output filename is passed in the method call, the folder paths can be changed using the variables.
static private void ExtractJPEGNames(string OutputFileName) // eg. "PicIDs.txt"
{
string sourcePath = @"E:\Source\";
string targetPath = @"E:\Destination\";
StreamWriter StrmWtr = new StreamWriter(targetPath + OutputFileName);
string[] tempArray = Directory.GetFiles(sourcePath);
List<string> filesInFolder = new List<string>();
foreach (string fileName in tempArray)
{
string tempID = fileName.Substring(fileName.LastIndexOf('\\') + 1, 3);
if (!filesInFolder.Contains(tempID))
filesInFolder.Add(tempID);
}
foreach (string fileID in filesInFolder)
{
StrmWtr.WriteLine(fileID);
}
StrmWtr.Flush();
StrmWtr.Close();
}