|
When I do drag and/or drop with files, I use a collection of actual files, just like the "regular" Windows Explorer does - there's even a DataFormat for them!
Keep your drag and drop separate: your Drop is relying on the ItemDrag event of your Source setting up your names appropriately. Don't do that: Make the source provide the info, and the Destination accept them.
The way I accept them is like this:
private void frmMusicTrackRename_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
dgvTracks.Rows.Clear();
LoadFiles(files);
}
(It's part of something I wrote when I realised my music collection had three different track naming styles, and wanted to unify them.)
And don't use string concatenation to assemble a full path - use Path.Combine Method (System.IO)[^] instead as it will apply the separaters intelligently.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
This is working by adding files from Windows Explorer to the list view. But when i add a "File" from another listview it doesn't work. The path from the Files is always null. In my first listview i have not the file itself. It's only a graphic wich represents the file.
Any further ideas?
Thanks
|
|
|
|
|
That would be because you aren't dragging them out of your listview as files - you are setting text format instead.
If you use the DataFormats.FileDrop Field (System.Windows)[^] it will allow you to drag them from your list box into anything which accepts files (inclding Explorer, Chrome, Word, ...)
It's not difficult!
Handle the MouseDown event for your ListView (this uses a DataGridView because I had one handy with files in a current project, and uses the right mouse button so I don't muck up my other code!)
private void myDataGridView_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
List<string> files = new List<string>();
foreach (DataGridViewRow row in myDataGridView.Rows)
{
files.Add((string)row.Cells["Location"].Value);
}
string[] selectedFiles = files.ToArray();
DataObject dragData = new DataObject(DataFormats.FileDrop, selectedFiles);
dragData.SetData(DataFormats.StringFormat, selectedFiles[0]);
DoDragDrop(dragData, DragDropEffects.Copy | DragDropEffects.Move);
}
}
That sets the list of files into the drag as files - you can now drop them on anything that accepts files!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Working fine!
Thanks again.
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
foreach (DataRow dataRow in dt.Rows)
{
if (dataRow["Column1"].ToString().Contains(["ExampleString"])
{
listBox1.Items.Add(dataRow["Column1"] + " " + dataRow["Column2"] + " " + dataRow["Column3"] + " " + dataRow["Column4"]);
}
}
string strFromCombobox = comboBox1.SelectedText;
foreach (DataRow dataRow in dt.Rows)
{
if (dataRow["Column1"].ToString().Contains(strFromCombobox)
{
listBox1.Items.Add(dataRow["Column1"] + " " + dataRow["Column2"] + " " + dataRow["Column3"] + " " + dataRow["Column4"]);
}
}
|
|
|
|
|
This is where you learn to use the debugger. Set a breakpoint on the if statement and inspect the contents of the strFromCombobox varaible. The debugger is there to show you how the code actually works instead of you guessing at it.
We really can't tell you why it fails because we can't see the contents of that variable. What every it is, it's matching content in Column1 of every row.
|
|
|
|
|
Likely not. SelectedText is the text the user has selected in the editable portion. I am guessing this is WinForms, so the property you want is SelectedItem[^], although you will need to cast it to a string.
This is all I can really do, as we don't know what type of object is in the combobox. If it's a string, great. Otherwise more logic may be needed.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
This is the code. The value has been changed to selecteditem but still not working
SqlDataAdapter da = new SqlDataAdapter();
DataSet1 ds = new DataSet1();
DataTable dt = new DataTable();
string tm = comboBox1.SelectedItem.ToString();
da.SelectCommand = cmd;
da.Fill(ds, "GameResults2015");
dt = ds.Tables["GameResults2015"];
MessageBox.Show(tm);
foreach (DataRow dataRow in dt.Rows)
{
if (dataRow["Winner/tie"].ToString().Contains(tm) || dataRow["Loser/tie"].ToString().Contains(tm))
{
listBox1.Items.Add(dataRow["Winner/tie"] + " " + dataRow["PtsW"] + " Loser " + dataRow["Loser/tie"] + " " + dataRow["PtsL"]);
}
}
|
|
|
|
|
I guess you need to also remove items that do not contains the selected string.
Philippe Mori
|
|
|
|
|
You really should follow Dave's advice and start using the debugger. Using the debugger isn't a crazy idea, it's what almost every developer does on a regular, if not even on a daily basis. It is essential to being as productive as possible as a developer - you would probably already know the solution to your problem here if you had used the debugger instead of writing the question.
So.. place a debug-breakpoint on that if-statement, hit F5 and when your program reaches that breakpoint, inspect the value of the variable(s) in question by hovering with the mouse cursor over it. That's all - neither difficult nor dangerous
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I had already debugged and there was nothing wrong with the result being returned at that stage of the method.
It turns out the problem was, I copied a list of names from the web, and pasted them into the comboBox. Evidently it didnt put them in as separate strings even though it showed each one on a new line. When I went back and entered the names manually it worked perfectly.
Thanks to everyone for your assistance
|
|
|
|
|
I am just getting started on building a workflow engine. I know I can build tasks in DLLs using the Workflow Foundation or to trigger a stand-alone executable but I am looking to add in the ability to write the task code in a scripting language similar to JavaScript, TypeScript, or LUA. I know this is a broad question but I don't really know where to start. Is it even possible? If it is, would this be a major endeavor or something relatively simple?
if (Object.DividedByZero == true) { Universe.Implode(); }
Meus ratio ex fortis machina. Simplicitatis de formae ac munus. -Foothill, 2016
|
|
|
|
|
There's a proud history of hosting languages inside C# applications. One you'll often find mentioned is IronPython.NET. There's an example showing how to host it here[^]. Hopefully that will get you started.
This space for rent
|
|
|
|
|
Thanks for the link. I visited the website and noticed that there has not been an update to IronPython.NET since 2014. Should I be concerned?
if (Object.DividedByZero == true) { Universe.Implode(); }
Meus ratio ex fortis machina. Simplicitatis de formae ac munus. -Foothill, 2016
|
|
|
|
|
You have a ton of options for scripting languages. If the choice of scripting language is not driven by the anticipated skills of the future users then I would suggest using C# for scripting. One of the most prominent solutions is CS-Script[^]. With Roslyn there's a relatively new solution, potentially even better (I haven't used it yet): roslyn scripting - Google Search[^]
Foothill wrote: would this be a major endeavor or something relatively simple? Somewhere inbetween unless you decide to create your own DSL, which will make it a major endeavor but could potentially be the best solution if one of your goals is to make it as user-accessible as possible.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Thanks for the links. I've heard of Roslyn but I never looked into it before. I like the idea of being able to write a C# workflow in text, store it anywhere (file, database), and execute it when needed.
if (Object.DividedByZero == true) { Universe.Implode(); }
Meus ratio ex fortis machina. Simplicitatis de formae ac munus. -Foothill, 2016
|
|
|
|
|
Roslyn is awesome. I really like it.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Jint[^] is a JavaScript interpreter written in C#.
If you don't mind importing native DLLs, PythonNET[^] is quite cool.
Roslyn has been mentioned already, and the official repo is on Github[^] (Beware, the build process can be quite finicky at times, failing for no obvious reason)
NLua[^] allows .NET applications to leverage the Lua language (currently Lua 5.2).
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Jint looks interesting. I will have to follow it.
Brisingr Aerowing wrote: Beware, the build process can be quite finicky at times, failing for no obvious reason
Interestingly enough, I used to work with MS System Center Orchestrator and one thing I really liked about it was that you could write actual C# code to be used anywhere in a Runbook. I don't know why I didn't think of it before because it was using Compiler Services the whole time. It too would throw some cryptic errors when I forgot to put the end quote on a string literal or a parameter was empty.
if (Object.DividedByZero == true) { Universe.Implode(); }
Meus ratio ex fortis machina. Simplicitatis de formae ac munus. -Foothill, 2016
|
|
|
|
|
The errors from Roslyn are pretty much always to the point and actually tell you what went wrong.
I don't use Jint, so I can't say what it's like.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
I've been looking at about a dozen flavors of scripting strategies for C# including those mentioned here (but, not Lua, Python, or IronPython). There's lots of open-source projects going on that offer scripting from light to heavy.
Defining what the facilities you need now, and in the future, seems to me the most criteria for choice of package. And, one can use T4, or .NET's compiler-services to generate code, or objects, on-the-fly, compile, run, instantiate the objects, etc.
One interesting script language for C# I have been exploring is Jing Lu's ReoScript; he used that in the ReoGrid project that he presented in an article here (just look it up); Jing made the choice to move ReoGrid from open- to closed-source some time ago, but his last open-source version is still up here. AFAIK ReoScript is still available as open-source: [^].
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
There seems to be a lot of competing scripting implementations for .Net. I do happen to be gravitating to Roslyn as you can write normal C#/VB code outside of a library and execute it inside the CLR. The idea of writing all your workflows in text and placing them in any storage medium, granting the workflows a level of independence from the program which executes them, affords system architects a level of flexibility that is hard to ignore.
if (Object.DividedByZero == true) { Universe.Implode(); }
Meus ratio ex fortis machina. Simplicitatis de formae ac munus. -Foothill, 2016
|
|
|
|
|
Is there any plugin or provision for End user can build a query and generate a Chart.
Example: My application have a list of master items, i can select master item and make a project. Consider i have 20 master items in which 5 projects are In Progress, 5 are Completed projects and 10 items Not started a Project yet. Based on this i want to draw a pie chart or a bar chart.
|
|
|
|
|
Where does the data come from and how is it managed? And when you say 'plugin', plugin for what? Please put some proper detail in your question.
|
|
|
|