|
If this is possible, please tell me how I can generate a set of constants which...
-- I can be reasonably certain are each mathematically unique
-- I don't have to assign individually, one-by-one with my keyboard.
ints will be fine.
I wrote out a long explanation of what I'm after, so if this doesn't make sense, just ask and I'll post a more involved explanation.
|
|
|
|
|
Enums[^]
enum zeConstants: int
{
bla1,
CListCtrl,
bacon,
StarWars = 7
}
static void Main()
{
foreach (zeConstants flag in Enum.GetValues(typeof(zeConstants)))
{
Console.WriteLine("{0} = {1}", flag, (int)flag);
}
Console.ReadLine();
}
|
|
|
|
|
Just discovered this, just guessing, never saw it before.
Looked it up on MSDN and DUH !!! They don't have it referenced !
Please, I gotta be wrong on that. Correct me and show me where, and what this is doing, and where the syntax is defined..
public enum UniqueValue
{
Fred,
Barney,
Dino,
BamBam,
Pebbles,
MrSlate,
Arnold
}
If that does what I'm hoping it does, then I am one step closer to my goal of legible sensible source code
|
|
|
|
|
C-P-User-3 wrote: Please, I gotta be wrong on that. Correct me and show me where, and what this is doing, and where the syntax is defined..
The code you have the would create a constant flag, used as "UniqueValue.Fred" for 0, or "UniqueValue.Barney" for 1. There's some examples here[^].
|
|
|
|
|
Got confused when the C# IDE put "UniqueValue" in bright pink on my screen. I thought I had stumbled onto a keyword.
|
|
|
|
|
C-P-User-3 wrote: Got confused when the C# IDE put "UniqueValue" in bright pink on my screen.
Pink??
http://studiostyl.es/[^]
|
|
|
|
|
Pink ? Strong purple ? I don't know what to call it.
Whatever, whatever, my education continues and now I'm so smart that I know that the color changed because it follows the "enum", and not only that, I think I'm getting this stuff about
public enum Zyxwvut
{
OneValue,
AnotherValue,
WhateverValue,
AndSoOn
}
Clear in my head, even the syntax with the colon and the type before the opening bracket.
Thanks for the pointer to the syntax page. I thought "UniqueValue" was a keyword or something, stuck it into the search thing on msdn and came up with zero; at which time I had a major DUH moment. Your suggestion clarified a lot for me. Thanks a ton.
|
|
|
|
|
They have contests for who has the best studio styles now ?
Hmmm, I wonder, you know; that's really not a bad idea.
Later, gotta get this done for the boss so I can keep my job
|
|
|
|
|
Hold it, wait a minute, on that msdn page, I just read this...
From the MSDN page: Usually it is best to define an enum directly within a namespace so that all classes in the namespace can access it with equal convenience. However, an enum can also be nested within a class or struct. I thought that every variable had to be in a class; but then these aren't variables; I guess; somebody fix my brain on this matter.
So then, if I take the enum thing (what is the right word for "thing" in this context ?) out of the class structure, and just put it after the opening bracket of the namespace, I can use the names in the enum list as they are ? Without the UniqueValue.Fred nomenclature ?
e.g., I could just use the name "Fred" (no quotes" and get a guaranteed unique value ?
|
|
|
|
|
An enumeration is a class. There are cases where you use typeof(MyEnum) .
C-P-User-3 wrote: I could just use the name "Fred"
Only in VB. But it's not a good idea.
|
|
|
|
|
C-P-User-3 wrote: I can use the names in the enum list as they are ? Without the UniqueValue.Fred nomenclature ?
It "has" to have the "UniqueValue" prefix; you could perhaps omit it if it were local to the class, but it'd be gross.
It'll be "namespace.enumname.value"
|
|
|
|
|
C-P-User-3 wrote: Looked it up on MSDN and DUH !!! They don't have it referenced ! No? What about this reference[^]?
Perhaps it would be worth getting hold of a good reference on C# (.NET Book Zero[^] is a reasonable start), rather than trying to learn from CodeProject questions.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Richard MacCutchan wrote: Perhaps it would be worth getting hold of a good reference on C# (.NET Book Zero[^] is a reasonable start), rather than trying to learn from CodeProject questions. Now that is a very useful resource. Thank you; like, a lot.
This captured my attention...From Petzold's Book: The latest version of Windows—Microsoft Windows Vista—includes the .NET Framework 3.0 Reading various websites and news stories, the word "Metro" gives me this mildly creepy feeling.
i.e., I'm studying trailing edge technology which nobody will want next year.
For the moment, I say thank you; it appears to be a useful thing to read.
Well yes; for the moment.
|
|
|
|
|
C-P-User-3 wrote: i.e., I'm studying trailing edge technology which nobody will want next year. On the contrary, there will be many businesses that will take years to move up to Windows 7, let alone Metro. Also learning the basics of .NET and C# will give you a solid grounding for learning all the new technology that is coming along.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Metro and WinRT are built on .Net, although the UI comes from Silverlight/WPF which is .Net 3.5 I think. But the language is the same, the core libraries are the same, and learning .Net 3.0 will give you a very good grounding in everything important that you'll need to be able to pick up WPF based approaches.
|
|
|
|
|
Thank you Richard and Bob.
Hope you are both correct.
|
|
|
|
|
Hey guys,
Easy one here. I want to see the results of my datatable in the DataGridView. When i execute, it runs without errors but no DataGridView shows up on screen. Does DataGridView require a form to view the results or something?
What am I missing?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FileHelpers;
using System.Data;
using System.IO;
using System.Data.OleDb;
using System.Windows.Forms;
namespace CSVParser
{
class CSVParser
{
public static DataTable ParseCSV(string path)
{
if (!File.Exists(path))
return null;
string full = Path.GetFullPath(path);
string file = Path.GetFileName(full);
string dir = Path.GetDirectoryName(full);
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;"
+ "Data Source=\"" + dir + "\\\";"
+ "Extended Properties=\"text;HDR=No;FMT=Delimited\"";
string query = "SELECT * FROM " + @"C:\Users\rsharp\Desktop\CustomerExport.csv";
DataTable dTable = new DataTable();
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
dAdapter.Fill(dTable);
DataGridView dgView = new DataGridView();
BindingSource bSource = new BindingSource();
bSource.DataSource = dTable;
dgView.DataSource = bSource;
dAdapter.Dispose();
return dTable;
}
}
}
modified 21-Nov-12 19:21pm.
|
|
|
|
|
RickSharp wrote: Doesn DataGridView require a form to view the results or something?
Yes, it does. It needs to be assigned to the Controls collection of the form that it's supposed to show on.
Where's the entry-point of your application?
|
|
|
|
|
By entry point do you mean is it just a win form, exe or class library? If so I have added a form project and console application project to my solution. So I have a class library that contains that code. I added a reference to that class library in the new forms and console projects that I created. I tried following this tutorial with no success.
http://www.dotnetperls.com/datagridview-tutorial[^]
|
|
|
|
|
RickSharp wrote: By entry point do you mean is it just a win form, exe or class library? If so I have added a form project and console application project to my solution. So I have a class library that contains that code. I added a reference to that class library in the new forms and console projects that I created. I tried following this tutorial with no success.
The tutorial has some different code than you have; A console-application doesn't show a form usually. There's also no need for a separate class-library - simply put then in a normal forms-application.
|
|
|
|
|
I have 2 texboxes and 1 button
TextBoxSearch.Text;
TextBoxName.Text;
and 1 button(searchbutton)
The thing i want to do is when i press the Search button and type an id in textboxsearch.text ( so the id will get the data and pass it in my textboxname.text
I have written so long ,
var sr=new ServiceReferens1.Product();
//here i have tryed
// TextBoxSearch.Text=sr.ProductID;
// and many more thing have i tryed so i need help!
|
|
|
|
|
Workflow
1. Enter search criteria in textbox1
2. Click button
3. Find record (details)
4. Display Results in textbox2
In the button click event do the following
1. Get the list of products
2. Use a linq query or a for..next loop to locate the product record base on you criteria
3. Set the located product in a SelectedProduct object (to be used later)
4. Set the SelectedProduct.ProductName into the textbox2
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have been thinking about this for a while and have not come up with any simple and beautiful ways to solve this problem. What I would like to have done is a nice way to sort Lists along side other Lists. Such as shown in the example:
I have a generic amount of Lists (let us just say 4) and they are independent of each other but are of same length.
listOne = [09,06,04,03]
listTwo = [20,50,40,30]
listThree = [15,45,85,65]
listFour = [89,39,19,99]
Now I would like to organize listOne but also move the indices of listTwo and listThree:
listOne = [03,04,06,09]
listTwo = [30,40,50,20]
listThree = [65,85,45,15]
I then work with these lists as I see fit. Now I would like to organize listFour but move listOne, listTwo and listThree with it:
listFour = [19,39,89,99]
listOne = [06,04,03,09]
listTwo = [50,40,30,20]
listThree = [45,85,65,15]
Is there already a development that does something like this? A way to organize any list and move the indexes of any number of extra lists with the organization of the first list. Right now I use the Dictionary type and have each indexed, then when one is organized, move the others with respect to the new Dictionary index. But that seems to be very sloppy.
|
|
|
|
|
Option 1:
It's not clean, but if you want to sort the lists, this should work:
static void Sort<T>(IList<T> sortKey, params IList<T>[] otherLists)
{
Action<IList<T>, IDictionary<int, int>> sortList = (list, keys) =>
{
var values = list
.Select((value, i) => new { key = keys[i], value })
.OrderBy(p => p.key).Select(p => p.value);
int index = 0;
foreach (T value in values)
{
list[index++] = value;
}
};
var indices = Enumerable.Range(0, sortKey.Count)
.OrderBy(i => sortKey[i])
.Select((key, value) => new { key, value })
.ToDictionary(p => p.key, p => p.value);
sortList(sortKey, indices);
foreach (var list in otherLists)
{
sortList(list, indices);
}
}
Edit:
Missed a ToList call in the anonymous delegate which would prevent this from working. Option 2 is probably a better approach.
Edit 2:
Nope, the ToList call isn't needed - the OrderBy call ensures that the entire sequence is evaluated on the first call to MoveNext .
It still ends up creating a copy of the list, so option 2 is still better.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
modified 22-Nov-12 7:15am.
|
|
|
|
|
Your issue is that you are trying to sort your lists as 4 different lists when they aren't. It's a single list of x items.
So just have:
class SomeObject
{
int Data[4];
}
List<SomeObject> lst;
When you sort, you would provide a custom compare function that'll look like:
int Compare(SomeObject x, SomeObject y)
{
compare x.Data[0] vs. y.Data[0] or whatever
}
and all "columns" will move together.
|
|
|
|
|