|
Right. Obviously!
So you understand that "car" is a generic word, but that each vehicle that is a "car" is separate and distinct. "My car" is not the same as "your car" - it shares some generic characteristics such as the number of wheels, and that it has an engine (or engines) but most of it's attributes are specific to a particular vehicle.
In computing, we call "car" a class and a specific vehicle an instance of that class, with the properties of an instance being defined by the class but "filled in" by the instance:
class Car
{
Color Color {get; set;}
Manufacturer Manunfacturer {get; set;}
}
...
Car myCar = new Car() { Color = Colors.Black, Manufacturer = Manufacturers.Mercedes};
Car yourCar = new Car() { Color = Colors.Red, Manufacturer = Manufacturers.Ford};
If you respray yourCar blue, it doesn't affect the colour of myCar - you know that!
So if your code creates just one instance of an InvoiceLine, what happens if you set the properties over and over again?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
thank for you help
but i think it's hard create instance to each new line in invoice lines
first i used this code to see result
string[,] datavalu = new string[dataGridView1.Rows.Count, dataGridView1.Columns.Count];
foreach(DataGridViewRow row in dataGridView1.Rows)
{
foreach (DataGridViewColumn col in dataGridView1.Columns)
{
datavalu[row.Index, col.Index] = dataGridView1.Rows[row.Index].Cells[col.Index].Value.ToString();
}
}
int i = 0;
foreach(string ss in datavalu)
{
listBox1.Items.Add(ss);
i++;
}
I think I thought wrong from the start. Often there are simpler ways Do you know a better way
|
|
|
|
|
Quote: i think it's hard create instance to each new line in invoice lines
Why?
You do it pretty easily when you create the one you do use!
So why do you think it is going to be harder to create them when you actually need them?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
thanks a lot
for ( i = 0; i < datavalu.GetLength(0); i++)
{
InvoiceLine invoiceline2 = new InvoiceLine();
invoiceline2.description = datavalu[i, 0].ToString();
invoiceline2.itemType = datavalu[i, 1].ToString();
invoiceline2.itemCode = datavalu[i, 2].ToString();
invoiceline2.internalCode = datavalu[i, 3].ToString();
invoiceline2.unitType = datavalu[i, 4].ToString();
invoiceline2.quantity = int.Parse(datavalu[i, 5].ToString());
invoicelines.Add(invoiceline2);
}
my mistake was
InvoiceLine invoiceline = new InvoiceLine();
create instants before loop
|
|
|
|
|
That's the one.
Though I'd have just moved the original line into the loop!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Find whoever put "Food2" in there and stone them.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hi
{
if (DataGridView2.Rows.Count != 0 && !string.IsNullOrEmpty(column_num.Text) && !string.IsNullOrEmpty(row_num.Text) && !string.IsNullOrEmpty(Equip_column.Text) && !string.IsNullOrEmpty(prog_num.Text))
{
for (int i = Convert.ToInt32(row_num.Text); i < DataGridView2.Rows.Count; i++)
{
if (!code_dic.ContainsKey(DataGridView2.Rows[i].Cells[Convert.ToInt32(column_num.Text)].Value.ToString()))
{
code_dic.Add(DataGridView2.Rows[i].Cells[Convert.ToInt32(column_num.Text)].Value.ToString(), string.Join(",", DataGridView2.Rows[i].Cells[Convert.ToInt32(Equip_column.Text)].Value.ToString(), prog_num.Text.ToString()));
}
}
}
foreach (KeyValuePair<string, string> pair in code_dic)
{
string[] my_arr = pair.ToString().Split(',');
my_table_code.Rows.Add(my_arr[0], my_arr[1], my_arr[2]);
DataGridView3.DataSource = my_table_code;
}
}
In the code above, dictionary puts information inside [ ] mark.
The output shows information like this:
[abc,def,ghi]
I want to omit [ ] marks. What to do?
|
|
|
|
|
Alex Dunlop wrote: In the code above, dictionary puts information inside [ ] mark. Where does this happen, and how are you checking it?
|
|
|
|
|
The code puts Dictionary into a data table and then, datatable in brought into DataGridView.
The result is reflected in DataGridView. It has 3 cloumns. Column 1 and 3 has "[" and "]" marks.
Something like this:
column 1....columns 2....column 3
[abcd........efgj..........ijkl]
|
|
|
|
|
That does not make it much clearer and your code is almost impossible to understand. You are using strings as column numbers, which means you have to convert them back to integers. You call ToString on a KeyValuePair<string, string> and then Split on the result, instead of taking the returned items as is. Chances are that whatever you are doing is affecting the text values you are storing. A few minutes with the debugger will show you where.
|
|
|
|
|
Took me less than a minute to see that:
pair.ToString()
returns the key and value surrounded by square brackets:
KeyValuePair<string, string> foo = new KeyValuePair<string, string>("foo", "bar");
Console.WriteLine(foo.ToString());
Output:
[foo, bar]
|
|
|
|
|
Yeah, you're right.
Is there any way to avoid that or remove it?
|
|
|
|
|
Good spot, @Richard_MacCutchan!
How about changing
string[] my_arr = pair.ToString().Split(',');
my_table_code.Rows.Add(my_arr[0], my_arr[1], my_arr[2]); to
string[] my_arr = pair.Value.Split(',');
my_table_code.Rows.Add(pair.Key, my_arr[0], my_arr[1]); ?
Note: This is off the top of my head, not tested. Caveat Emptor.
modified 20-May-21 6:05am.
|
|
|
|
|
|
[] is the C# syntax for indexing: it's used with a numeric value for ordered Collections, and other types of values with Collections like Dictionary<TKey, TValue> that have no inherent ordinality.
That's just the way the language is.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Hi,
i would to make an explorer to add some methods i need behind. I tried a lot of things but many are deprecated. I'm under windows 10 x64. I want to make my app under .net core.
I tried SHGetSpecialFolderLocation but the name i retrieve is in chinese... i don't understand why. I saw with windows 10 it's better to use knownfolderid but i search in my registrykeys and i didn't find mega key, but it uses a clsid. Should it a good idea to ask to the registry or is there another method ?
i want to make something classic, with "mycomputer" root, make drives under it (it's ok for this part), have clouds folder also... And i will try to get default icons, i have some methods using win32.dll (if you have better i will happy to have more informations).
|
|
|
|
|
You haven't explained any kind of problem you're having.
I'm going to guess that you're trying to use SHGetSpecialFolder location to get the paths to cloud folder. That will not work as they are not part of the Windows file system.
AFAIK, there is no standard method to get cloud folder paths. You'd have to write support modules for each cloud provider you want to support and ask the user for their username and password to get into those folders.
|
|
|
|
|
hi, thanks for your answer.
I tried several things, even before i tried to read sources from this example
I used
IntPtr m_pIDL = IntPtr.Zero;
hRes = ShellAPI.SHGetSpecialFolderLocation(IntPtr.Zero, CSIDL.CSIDL_DESKTOP, ref m_pIDL); but it's deprecated, so i used
hRes = ShellAPI.SHGetFolderLocation(IntPtr.Zero, 0, IntPtr.Zero,0, out m_pIDL);
For retrieve informations i used
SHFILEINFO shInfo = new SHFILEINFO();
ShellAPI.SHGetFileInfo(m_pIDL, 0, out shInfo, (uint)Marshal.SizeOf(shInfo),
SHGFI.DisplayName |
SHGFI.PIDL |
SHGFI.SmallIcon |
SHGFI.SystemIconIndex
);
But i get
畂敲畡 as display name, and 34 as iIcon in all cases. Which means "toc toc" (knocking) according to google translate.
I can't go more forward, i'm totally blind because of that.
This example is interesting because it give me what i need, i have one drive & mega folders and it seems there is no special instruction to have it, it lists elements by using
EnumObjects
This is why i would to use some elements under .net core and learn how to use windows api, instead of using c# with methods from Directory. If i understand well it's a handle (pointeur?).
SHFILEINFO
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct SHFILEINFO
{
public IntPtr hIcon;
public int iIcon;
public uint dwAttributes;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szTypeName;
}
[DllImport("shell32.dll")]
public static extern int SHGetFolderLocation(IntPtr hwndOwner, int csidl, IntPtr hToken, uint dwReserved, out IntPtr ppidl);
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SHGetFileInfo(string path, uint attributes, out SHFILEINFO fileInfo, uint size, uint flags);
[DllImport("shell32.dll")]
public static extern IntPtr SHGetFileInfo(IntPtr pIDL, uint dwFileAttributes, out SHFILEINFO psfi, uint cbFileInfo, uint uFlags);
#endregion
modified 19-May-21 20:13pm.
|
|
|
|
|
What's the return value from your SHGetFileInfo call. If it's 0, then some error occurred and you're going to have to use GetLastError to get the error code to see what happened.
|
|
|
|
|
Hi, i have an hexadecimal value for the return value.
I ask myself if i must continue to this way, i read somewhere else it was an old way to do it like a c++ copy/paste. I would to have something quick, with all default icons (i don't know another way for folders than to use win32.dll this is why i thought about make all with api methods)
Meanwhile, to go forward i found a way to get mega folders, i post here if it can help others.
var identity = System.Security.Principal.WindowsIdentity.GetCurrent();
string userName = identity.Name.ToString();
string userSID = identity.User.ToString();
List<string> MegaFolderPaths = new List<string>();
RegistryKey clsidKey = Registry.Users.OpenSubKey($"{userSID}\\Software\\Classes\\CLSID");
foreach (string subKey in clsidKey.GetSubKeyNames())
{
RegistryKey clsidSubKey = Registry.Users.OpenSubKey($"{userSID}\\Software\\Classes\\CLSID\\{subKey}\\Instance\\InitPropertyBag");
if (clsidSubKey == null)
continue;
string defaultValue = (string)clsidSubKey.GetValue("TargetFolderPath");
if (!string.IsNullOrEmpty(defaultValue))
MegaFolderPaths.Add(defaultValue);
}
-------------------
Edit: for the chinese character i didn't see i forgot to add this
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
above
public static extern Int32 SHGetFileInfo(IntPtr pIDL, uint dwFileAttributes,
out SHFILEINFO psfi, uint cbFileInfo, uint uFlags);
modified 21-May-21 3:29am.
|
|
|
|
|
(beginner question)
I have a small app and a Class Library that generate a DLL and an EXE.
I read that I can use ILMerge to merge the DLL and EXE together.
The NuGet says the package is deprecated:
"This package has been deprecated as it is legacy and no longer maintained"
Is there something newer or another way to do this, merge the DLL and EXE ?
Thanks.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
|
I am trying to replace a text with something. most often it works but for a particular text replace not working. here is the code example.
string maindata = "Operational Metrics~Domestic Subscribers Disney+~2015 FY~9999";
string data = "Operational Metrics~Domestic Subscribers Disney+~2015 FY~9999";
string strformula = Regex.Replace(maindata, "\"" + data.Replace("(", "\\(").Replace(")", "\\)").Replace("$", "\\$") + "\"", "W51",RegexOptions.IgnoreCase);
strformula = maindata.Replace("\"" + data.Replace("(", "\\(").Replace(")", "\\)").Replace("$", "\\$") + "\"", "W51");
i tried both Regex.Replace() & String.Replace() but no luck. what is so special in the text "Operational Metrics~Domestic Subscribers Disney+~2015 FY~9999" for which replace not working ?
please give me some direction. thanks
|
|
|
|
|
It might help if you could give some before and after examples, from what I can see nothing would change from the test data provided.
Do yourself a favour and don't chain the replace statements like that as it makes it difficult to see what is going on and almost impossible to debug and is a maintenance nightmare and is neither clever or helpful.
Split the whole line into discrete steps so you can examine what the before and after values are at each replace step.
|
|
|
|
|
Here i am posting simple replace. please run at your side then understand Replace() not able to replace.
string maindata = "Operational Metrics~Domestic Subscribers Disney+~2015 FY~9999";
string data = "Operational Metrics~Domestic Subscribers Disney+~2015 FY~9999";
string strformula = Regex.Replace(maindata, data , "W51",RegexOptions.None);
try my above code and must notice replace not able to replace Operational Metrics~Domestic Subscribers Disney+~2015 FY~9999 with W51
Thanks
|
|
|
|
|