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
Temporal Nightmare
Temporal NightmareOP•7mo 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•7mo 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
Temporal Nightmare
Temporal NightmareOP•6mo 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•6mo ago
still, where is _loggingUserControl populated here?
Temporal Nightmare
Temporal NightmareOP•6mo ago
its not ai did it for me :/ cuz i was stuck and couldnt wait lol
Temporal Nightmare
Temporal NightmareOP•6mo ago
No description
Temporal Nightmare
Temporal NightmareOP•6mo ago
even if i use it, this is an issue
ero
ero•6mo ago
i wouldn't presume such a method exists on that type
Temporal Nightmare
Temporal NightmareOP•6mo 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•6mo 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
Temporal Nightmare
Temporal NightmareOP•6mo ago
its not all ai, just asked it to help after I posted here yesterday
ero
ero•6mo ago
test the code, write your own, come back when there's problems
Temporal Nightmare
Temporal NightmareOP•6mo ago
ok
ero
ero•6mo ago
we're happy to help, but don't ask "will this work" please test it
Temporal Nightmare
Temporal NightmareOP•6mo ago
okay, gimmie a bit well I went through it but still stuck
ero
ero•6mo ago
sure, what's the problem
Temporal Nightmare
Temporal NightmareOP•6mo 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•6mo ago
this isn't really mvvm :p
Temporal Nightmare
Temporal NightmareOP•6mo ago
i know but im getting older and i dont have time to mess around with it
ero
ero•6mo ago
you never added the item to the list ever
Temporal Nightmare
Temporal NightmareOP•6mo ago
dialogs are so much easier but no, someone told me to make it a webpage app because "courage"
ero
ero•6mo ago
this bit would work after this change previously you had to do Logger.WriteLog(HashBytesOutputTextBox.Text, _loggingUserControl)
Temporal Nightmare
Temporal NightmareOP•6mo 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•6mo ago
well you have a reference to LoggingUserControl in GenerateHashUserControl here so this can't be true
Temporal Nightmare
Temporal NightmareOP•6mo ago
ok im reposting this shit once more but on pastebin because im sick of discord's limits
ero
ero•6mo ago
$paste
MODiX
MODiX•6mo 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!
Temporal Nightmare
Temporal NightmareOP•6mo 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.
Temporal Nightmare
Temporal NightmareOP•6mo 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.
Temporal Nightmare
Temporal NightmareOP•6mo 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.
Temporal Nightmare
Temporal NightmareOP•6mo 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•6mo ago
i'm sorry but what are you even using to code?
Temporal Nightmare
Temporal NightmareOP•6mo ago
... VS 2022?
ero
ero•6mo ago
this doesn't compile
Temporal Nightmare
Temporal NightmareOP•6mo ago
because im using WinForms.. and bash me , i dont care im my own person
ero
ero•6mo ago
i'm not bashing, hah
Temporal Nightmare
Temporal NightmareOP•6mo ago
just saying, this is prototyping šŸ™‚
ero
ero•6mo ago
but i gotta make sure you're even using an IDE
Temporal Nightmare
Temporal NightmareOP•6mo ago
i am...
ero
ero•6mo ago
cause this line _loggingUserControl.WriteLog(_loggingUserControl., "Generated!"); would produce an error
Temporal Nightmare
Temporal NightmareOP•6mo ago
No description
ero
ero•6mo 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
Temporal Nightmare
Temporal NightmareOP•6mo 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•6mo ago
i don't think it has much to do with forms vs usercontrols
Temporal Nightmare
Temporal NightmareOP•6mo ago
here im done, herer is my solution
Temporal Nightmare
Temporal NightmareOP•6mo 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•6mo 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
Temporal Nightmare
Temporal NightmareOP•6mo 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•6mo 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
Temporal Nightmare
Temporal NightmareOP•6mo ago
No description
Temporal Nightmare
Temporal NightmareOP•6mo ago
store controls? they're right there ^
ero
ero•6mo 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
Temporal Nightmare
Temporal NightmareOP•6mo 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•6mo ago
so right now you're creating a new instance of LoggingUserControl in ShowGenerateHashControl, but you never do anything with it
Temporal Nightmare
Temporal NightmareOP•6mo 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•6mo ago
this new instance is of course separate from the control you create and show in SetupMeta
Temporal Nightmare
Temporal NightmareOP•6mo 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•6mo ago
so right here you instantiate and add the control to your form that's fine but in ShowGenerateHashControl, you create a new control
Temporal Nightmare
Temporal NightmareOP•6mo ago
i SHOULD make a new one?
ero
ero•6mo ago
no
Temporal Nightmare
Temporal NightmareOP•6mo ago
oh hold XD
ero
ero•6mo ago
that's what you're doing right now
ero
ero•6mo ago
No description
Temporal Nightmare
Temporal NightmareOP•6mo ago
No description
Temporal Nightmare
Temporal NightmareOP•6mo ago
am i close? minus the error XD
ero
ero•6mo ago
this would be one possibility, sure how do you think we can ideally deal with the error?
Temporal Nightmare
Temporal NightmareOP•6mo ago
public partial class GenerateHashUserControl : UserControl { private LoggingUserControl _loggingUserControl; public GenerateHashUserControl(_loggingUserControl) { InitializeComponent(); } by doing that not making a new one again
ero
ero•6mo ago
well, this is again not valid syntax, but you're getting there
Temporal Nightmare
Temporal NightmareOP•6mo ago
:/
ero
ero•6mo ago
i mean that shouldn't be surprising, vs should have already told you so :p
Temporal Nightmare
Temporal NightmareOP•6mo 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•6mo ago
take it slow :)
Temporal Nightmare
Temporal NightmareOP•6mo 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•6mo ago
no reason to give up yet. can always come back another time
Temporal Nightmare
Temporal NightmareOP•6mo 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•6mo ago
where are you exposing it?
Temporal Nightmare
Temporal NightmareOP•6mo ago
No description
Temporal Nightmare
Temporal NightmareOP•6mo ago
i even tried to make this shit public and thats a no no but i dont care still wont work
ero
ero•6mo ago
what do you mean by "won't work" an error message or wrong behavior would be helpful
Temporal Nightmare
Temporal NightmareOP•6mo 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•6mo ago
you should be able to just access namedLoggingListBox on any instance of LoggingUserControl
Temporal Nightmare
Temporal NightmareOP•6mo ago
No description
Temporal Nightmare
Temporal NightmareOP•6mo ago
this is why i cant get it on github the stupid shit is bugging out
ero
ero•6mo ago
can't say i've seen that before
Temporal Nightmare
Temporal NightmareOP•6mo ago
not surprised 😦
Temporal Nightmare
Temporal NightmareOP•6mo ago
No description
Temporal Nightmare
Temporal NightmareOP•6mo ago
ok so github works
Temporal Nightmare
Temporal NightmareOP•6mo ago
No description
Temporal Nightmare
Temporal NightmareOP•6mo 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
Temporal Nightmare
Temporal NightmareOP•6mo ago
No description

Did you find this page helpful?