C
C#ā€¢2mo ago
Core Dream

ListBox entries from UserControl not working.

public static class Logger
{
public static string WriteLog(string message)
{
return $"{DateTime.Now}: {message}";
}

public static void WriteLog(string message, LoggingUserControl loggingUserControl)
{
loggingUserControl.LogMessage(message);
}
}
public static class Logger
{
public static string WriteLog(string message)
{
return $"{DateTime.Now}: {message}";
}

public static void WriteLog(string message, LoggingUserControl loggingUserControl)
{
loggingUserControl.LogMessage(message);
}
}
public partial class LoggingUserControl : UserControl
{
private ListBox _loggingListBox;

public LoggingUserControl()
{
InitializeComponent();
_loggingListBox = LoggingListBox;
}

public void LogMessage(string message)
{
string formattedMessage = Logger.WriteLog(message);
_loggingListBox.Items.Add(formattedMessage);
}
}
public partial class LoggingUserControl : UserControl
{
private ListBox _loggingListBox;

public LoggingUserControl()
{
InitializeComponent();
_loggingListBox = LoggingListBox;
}

public void LogMessage(string message)
{
string formattedMessage = Logger.WriteLog(message);
_loggingListBox.Items.Add(formattedMessage);
}
}
private void GenerateHash()
{
if (HashInputTextBox.Text.Length > 0)
{
HashBytesOutputTextBox.Text = FNV1A.ByteArrayToString(FNV1A.HashToBytes(HashInputTextBox.Text.ToLower()));
Logger.WriteLog("Hash generated!",);
}
else
{
MessageBox.Show("Input is required!", "No Entry", MessageBoxButtons.OK);
}
}
private void GenerateHash()
{
if (HashInputTextBox.Text.Length > 0)
{
HashBytesOutputTextBox.Text = FNV1A.ByteArrayToString(FNV1A.HashToBytes(HashInputTextBox.Text.ToLower()));
Logger.WriteLog("Hash generated!",);
}
else
{
MessageBox.Show("Input is required!", "No Entry", MessageBoxButtons.OK);
}
}
91 Replies
Core Dream
Core DreamOPā€¢2mo ago
GenerateHash is in public partial class GenerateHashUserControl , which is a UserControl LoggingUserControl is also a UserControl (its in a panel on MainApp Logger is a helper class in its own class For the life of me, I am not getting any output to the listbox but the message exists.
ero
eroā€¢2mo ago
What calls LogMessage? Also the code doesn't compile and you have a stray WriteLog call in that last block that doesn't do anything
Core Dream
Core DreamOPā€¢2mo ago
using Discovery.Meta.UserControls;

namespace Discovery.Meta.Helpers;

public static class Logger
{
public static string WriteLog(string message)
{
return $"{DateTime.Now}: {message}";
}

public static void WriteLog(string message, LoggingUserControl loggingUserControl)
{
loggingUserControl.LogMessage(message);
}
}
using Discovery.Meta.UserControls;

namespace Discovery.Meta.Helpers;

public static class Logger
{
public static string WriteLog(string message)
{
return $"{DateTime.Now}: {message}";
}

public static void WriteLog(string message, LoggingUserControl loggingUserControl)
{
loggingUserControl.LogMessage(message);
}
}
If I was just doing a dialog, it would be easier but UC to UC is a bit different to me XD
using Discovery.Meta.Helpers;

namespace Discovery.Meta.UserControls;

public partial class GenerateHashUserControl : UserControl
{
private LoggingUserControl _loggingUserControl;

public GenerateHashUserControl(LoggingUserControl loggingUserControl)
{
InitializeComponent();
_loggingUserControl = loggingUserControl;
}

private void GenerateHashButton_Click(object sender, EventArgs e)
{
GenerateHash();
}

private void GenerateHash()
{
if (HashInputTextBox.Text.Length > 0)
{
HashBytesOutputTextBox.Text = FNV1A.ByteArrayToString(FNV1A.HashToBytes(HashInputTextBox.Text.ToLower()));
Logger.WriteLog("Hash generated!");
}
else
{
MessageBox.Show("Input is required!", "No Entry", MessageBoxButtons.OK);
}
}

private void HashInputTextBox_TextChanged(object sender, EventArgs e)
{
string formattedPath;
HashBytesOutputTextBox.Text = FNV1A.ByteArrayToString(FNV1A.HashToBytes(HashInputTextBox.Text.ToLower()));
HashValueOutputTextBox.Text = FNV1A.HashToULong(HashInputTextBox.Text.ToLower(), out formattedPath).ToString();
}
}
using Discovery.Meta.Helpers;

namespace Discovery.Meta.UserControls;

public partial class GenerateHashUserControl : UserControl
{
private LoggingUserControl _loggingUserControl;

public GenerateHashUserControl(LoggingUserControl loggingUserControl)
{
InitializeComponent();
_loggingUserControl = loggingUserControl;
}

private void GenerateHashButton_Click(object sender, EventArgs e)
{
GenerateHash();
}

private void GenerateHash()
{
if (HashInputTextBox.Text.Length > 0)
{
HashBytesOutputTextBox.Text = FNV1A.ByteArrayToString(FNV1A.HashToBytes(HashInputTextBox.Text.ToLower()));
Logger.WriteLog("Hash generated!");
}
else
{
MessageBox.Show("Input is required!", "No Entry", MessageBoxButtons.OK);
}
}

private void HashInputTextBox_TextChanged(object sender, EventArgs e)
{
string formattedPath;
HashBytesOutputTextBox.Text = FNV1A.ByteArrayToString(FNV1A.HashToBytes(HashInputTextBox.Text.ToLower()));
HashValueOutputTextBox.Text = FNV1A.HashToULong(HashInputTextBox.Text.ToLower(), out formattedPath).ToString();
}
}
ero
eroā€¢2mo ago
still, where is _loggingUserControl populated here?
Core Dream
Core DreamOPā€¢2mo ago
its not ai did it for me :/ cuz i was stuck and couldnt wait lol
Core Dream
Core DreamOPā€¢2mo ago
No description
Core Dream
Core DreamOPā€¢2mo ago
even if i use it, this is an issue
ero
eroā€¢2mo ago
i wouldn't presume such a method exists on that type
Core Dream
Core DreamOPā€¢2mo ago
using Discovery.Meta.Helpers;

namespace Discovery.Meta.UserControls;

public partial class LoggingUserControl : UserControl
{
private ListBox _loggingListBox;

public LoggingUserControl()
{
InitializeComponent();
_loggingListBox = LoggingListBox;
}

public void LogMessage(string message)
{
string formattedMessage = Logger.WriteLog(message);
_loggingListBox.Items.Add(formattedMessage);
}
}
using Discovery.Meta.Helpers;

namespace Discovery.Meta.UserControls;

public partial class LoggingUserControl : UserControl
{
private ListBox _loggingListBox;

public LoggingUserControl()
{
InitializeComponent();
_loggingListBox = LoggingListBox;
}

public void LogMessage(string message)
{
string formattedMessage = Logger.WriteLog(message);
_loggingListBox.Items.Add(formattedMessage);
}
}
ero
eroā€¢2mo ago
what's the idea here what do you expect people in this server to do when all you do is post a snippet of some ai-generated code
Core Dream
Core DreamOPā€¢2mo ago
its not all ai, just asked it to help after I posted here yesterday
ero
eroā€¢2mo ago
test the code, write your own, come back when there's problems
Core Dream
Core DreamOPā€¢2mo ago
ok
ero
eroā€¢2mo ago
we're happy to help, but don't ask "will this work" please test it
Core Dream
Core DreamOPā€¢2mo ago
okay, gimmie a bit well I went through it but still stuck
ero
eroā€¢2mo ago
sure, what's the problem
Core Dream
Core DreamOPā€¢2mo ago
namespace Discovery.Meta.Helpers;

public static class Logger
{
public static string WriteLog(ListBox listbox, string message)
{
return $"{DateTime.Now}: {message}";
}
}
namespace Discovery.Meta.Helpers;

public static class Logger
{
public static string WriteLog(ListBox listbox, string message)
{
return $"{DateTime.Now}: {message}";
}
}
you'd this this would work i stepped through both methods, it GETS the message but it never adds i hate usercontrol to usercontrol sharing I think I see 1 bug, hld nm f it i'll rip it out ands do it direct mvvm my ass did anyone use mvvm to do the space program? no or anything else oop 4 hours just to fix ONE issue
ero
eroā€¢2mo ago
this isn't really mvvm :p
Core Dream
Core DreamOPā€¢2mo ago
i know but im getting older and i dont have time to mess around with it
ero
eroā€¢2mo ago
you never added the item to the list ever
Core Dream
Core DreamOPā€¢2mo ago
dialogs are so much easier but no, someone told me to make it a webpage app because "courage"
ero
eroā€¢2mo ago
this bit would work after this change previously you had to do Logger.WriteLog(HashBytesOutputTextBox.Text, _loggingUserControl)
Core Dream
Core DreamOPā€¢2mo ago
im getting confused because there is a MAIN APP which talks to both user controls and the user controls can't talk to each user and im trying to do references ffs im about to say f website looks and use TRADITIONAL thisi s a pc not a damn phone
ero
eroā€¢2mo ago
well you have a reference to LoggingUserControl in GenerateHashUserControl here so this can't be true
Core Dream
Core DreamOPā€¢2mo ago
ok im reposting this shit once more but on pastebin because im sick of discord's limits
ero
eroā€¢2mo ago
$paste
MODiX
MODiXā€¢2mo ago
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
Core Dream
Core DreamOPā€¢2mo ago
Pastebin
// GenerateHashUserControl.cs!!!!using Discovery.Meta.Helpers;names...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Core Dream
Core DreamOPā€¢2mo ago
Pastebin
// LoggingUserControl.cs !!!!namespace Discovery.Meta.UserControls;...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Core Dream
Core DreamOPā€¢2mo ago
Pastebin
//MAIN APP!using Discovery.Meta.UserControls;namespace Discovery.Me...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Core Dream
Core DreamOPā€¢2mo ago
there im too tired to give a shit please šŸ˜¦ people act like I can sit on my ass 24/7 and code, I only get 2 hours a night
ero
eroā€¢2mo ago
i'm sorry but what are you even using to code?
Core Dream
Core DreamOPā€¢2mo ago
... VS 2022?
ero
eroā€¢2mo ago
this doesn't compile
Core Dream
Core DreamOPā€¢2mo ago
because im using WinForms.. and bash me , i dont care im my own person
ero
eroā€¢2mo ago
i'm not bashing, hah
Core Dream
Core DreamOPā€¢2mo ago
just saying, this is prototyping šŸ™‚
ero
eroā€¢2mo ago
but i gotta make sure you're even using an IDE
Core Dream
Core DreamOPā€¢2mo ago
i am...
ero
eroā€¢2mo ago
cause this line _loggingUserControl.WriteLog(_loggingUserControl., "Generated!"); would produce an error
Core Dream
Core DreamOPā€¢2mo ago
No description
ero
eroā€¢2mo ago
i'm not amazing at winforms mvvm anymore. the truly proper way to do this would be to add a List<string> to LoggingUserControl, bind the items of the ListBox (or whatever) to that list, and (i think) add an event on GenerateHashUserControl that's called when a new hash is created the binding can be difficult
Core Dream
Core DreamOPā€¢2mo ago
sorry šŸ˜¦ i'll try that not doing mvvm in winforms anyway so it's all ok lol just banging my head on my desk right now (not literally) I HATE UserControls in WinForms Because I am still having the same issue, when I used WINDOWS/Forms it worked! Maybe my dumb ass is using UserControls as PAGES and thinking its the same PAGES from WPF :/
ero
eroā€¢2mo ago
i don't think it has much to do with forms vs usercontrols
Core Dream
Core DreamOPā€¢2mo ago
here im done, herer is my solution
Core Dream
Core DreamOPā€¢2mo ago
i cant spend 3 nights in a row on a bs stupid thing i know i cant pay, its in the rules but im about to snap
ero
eroā€¢2mo ago
sorry, but i'm just not downloading and opening a random zip from the internet :p upload it to github or something of the sort
Core Dream
Core DreamOPā€¢2mo ago
i was just gonna send you 50,000 viruses from russia :/ just kidding i tried github but i cant get it to work im special apparently "special" :/ maybe i should go play with lego or toy blocks, its more my level it seems
ero
eroā€¢2mo ago
the problem i'm mainly seeing is that your controls look a bit all over the place you don't store your controls, for example
Core Dream
Core DreamOPā€¢2mo ago
No description
Core Dream
Core DreamOPā€¢2mo ago
store controls? they're right there ^
ero
eroā€¢2mo ago
store as in as a reference that you can access easily you need to retain a reference to your LoggingUserControl, for example, so that you can access it later again, to add items to it
Core Dream
Core DreamOPā€¢2mo ago
that I am aware but my brain is friend i only get 2-3 hours a night, i barely sleep, i have heart issues and require medical help so im on disability as well
ero
eroā€¢2mo ago
so right now you're creating a new instance of LoggingUserControl in ShowGenerateHashControl, but you never do anything with it
Core Dream
Core DreamOPā€¢2mo ago
and this is the only joy i have in my life lately and i cant even do it:/ i hate being older even though im acting 12 now >_> let me check, sec
ero
eroā€¢2mo ago
this new instance is of course separate from the control you create and show in SetupMeta
Core Dream
Core DreamOPā€¢2mo ago
ugh why private void SetupMeta() { PanelBottom.Controls.Clear(); var control = new LoggingUserControl(); control.Dock = DockStyle.Fill; PanelBottom.Controls.Add(control); } nothing in there
ero
eroā€¢2mo ago
so right here you instantiate and add the control to your form that's fine but in ShowGenerateHashControl, you create a new control
Core Dream
Core DreamOPā€¢2mo ago
i SHOULD make a new one?
ero
eroā€¢2mo ago
no
Core Dream
Core DreamOPā€¢2mo ago
oh hold XD
ero
eroā€¢2mo ago
that's what you're doing right now
ero
eroā€¢2mo ago
No description
Core Dream
Core DreamOPā€¢2mo ago
No description
Core Dream
Core DreamOPā€¢2mo ago
am i close? minus the error XD
ero
eroā€¢2mo ago
this would be one possibility, sure how do you think we can ideally deal with the error?
Core Dream
Core DreamOPā€¢2mo ago
public partial class GenerateHashUserControl : UserControl { private LoggingUserControl _loggingUserControl; public GenerateHashUserControl(_loggingUserControl) { InitializeComponent(); } by doing that not making a new one again
ero
eroā€¢2mo ago
well, this is again not valid syntax, but you're getting there
Core Dream
Core DreamOPā€¢2mo ago
:/
ero
eroā€¢2mo ago
i mean that shouldn't be surprising, vs should have already told you so :p
Core Dream
Core DreamOPā€¢2mo ago
having autism and adhd isn't helping me cuz i gott 5056340530630653063 windows and tabs open and i have to scroll in 4 chats to remember where i am šŸ˜­
ero
eroā€¢2mo ago
take it slow :)
Core Dream
Core DreamOPā€¢2mo ago
i am slow enough not kidding, I was always slow that way šŸ˜ just not in a good way heh I'm gonna try this one more time
ero
eroā€¢2mo ago
no reason to give up yet. can always come back another time
Core Dream
Core DreamOPā€¢2mo ago
that line is getting old, ive been told this since i was in my teens im almost 50 and nothing to show for it at all, so no, im not coming back another time, i need to do stuff while i can unless there';s a Lifespan DLC pack i can grab and now i lost the discussion, ugh, hold im getting confused because all i want is the ListBox namedLoggingListBox and use that but nope, im dumb
ero
eroā€¢2mo ago
where are you exposing it?
Core Dream
Core DreamOPā€¢2mo ago
No description
Core Dream
Core DreamOPā€¢2mo ago
i even tried to make this shit public and thats a no no but i dont care still wont work
ero
eroā€¢2mo ago
what do you mean by "won't work" an error message or wrong behavior would be helpful
Core Dream
Core DreamOPā€¢2mo ago
I JUST WANT TO ADD SHIT TO A LISTBOX why is it so fucking hard a child can do it/"!@E#$##!@#$!@$ god, i miss Commodore 64
ero
eroā€¢2mo ago
you should be able to just access namedLoggingListBox on any instance of LoggingUserControl
Core Dream
Core DreamOPā€¢2mo ago
No description
Core Dream
Core DreamOPā€¢2mo ago
this is why i cant get it on github the stupid shit is bugging out
ero
eroā€¢2mo ago
can't say i've seen that before
Core Dream
Core DreamOPā€¢2mo ago
not surprised šŸ˜¦
Core Dream
Core DreamOPā€¢2mo ago
No description
Core Dream
Core DreamOPā€¢2mo ago
ok so github works
Core Dream
Core DreamOPā€¢2mo ago
No description
Core Dream
Core DreamOPā€¢2mo ago
how the hell do i upload the rest of the files? o_O got it https://github.com/coredreamstudios/Discovery.Meta finally its private so i migh need to invite you i dont want my code public right now gonan try to sleep, have a good night and thank you for trying to help :), i might just try to sleep and try again tomorrow well i mastered it so much i got a listview to go šŸ˜Š i made a new project to test
Core Dream
Core DreamOPā€¢2mo ago
No description
Want results from more Discord servers?
Add your server