|
Can someone help with an issue I'm having with a CheckListBox.
I have two Forms lets say Form1 - Form2, Form2 contains a CheckListBox that accepts input from the user I've also created a Foreach statement to Iterate through the CheckListBox on Form2 Form1 has a button coded to call Form2 Foreach method everything seems to work except for one problem when making the call to Form2 the Foreach method indicates the CheckListBox is Null although the CheckListbox contains item's, so as a test I created a button on Form2 and wired it to call the Foreach method on Form2 and all works the Foreach Method see's the Item's and perform the Iteration on all Item's where as making the call from Form1 indicate a Null CheckListBox. I'm not sure if this is a Threading issue do to the fact Form1 is creating a new Object to access Form2 Foreach method ?
FORM1
button1_Click(object sender, EventArgs e)
{
List.Form2 List = new List.From2();
List.ChkList();
}
FORM 2
Public void ChkList()
foreach (string s in checkedListBox1.Items)
{
if (s.Equals(dt))
{ Do Work
}
FORM2 Test Button.
button2_Click(object sender, EventArgs e)
{
List.Form2 List = new List.From2();
List.ChkList();
}
|
|
|
|
|
Works without a problem on my system using the setup you described. It shouldn't be a threading issue based on what you said. It more than likely is an ordering issue of when the items in the list get populated. If you populate them on Load (only called when the Form is shown) or via some other event, those won't be called on construction. So, you might want to start there. Just place breakpoints around the sections that load data into that list and go from there.
|
|
|
|
|
the situation is completely unclear.
is it From2 or Form2?
is the "List" form shown at all, I see no List.Show()?
where is the declaration of checkedListBox1? and its assignment?
etc etc
and how could it be a threading issue, you haven't shown anything related to threads?
BTW: your button2_Click() method probably proves nothing as it (1) only can work after its Form is fully loaded and shown, (2) creates yet another "From2", and (3) is located inside Form2 class, so it is completely different from what button1_click() is doing.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thanks Luc, Im new to the forum and was in a rush and left out details on the other hand the Info Dave and Andrew left might be enough to get me back on track.
|
|
|
|
|
What you're trying to do, or at least the way you're trying to do it, seems a little bit strange.
This code works for me. Just a default project with a Form1 and Form2 added - everything else in done in code.
using System;
using System.Windows.Forms;
public partial class Form1 : Form
{
private Form2 form2;
public Form1()
{
InitializeComponent();
Button button = new Button();
Controls.Add(button);
button.Click += button_Click;
}
void button_Click(object sender, EventArgs e)
{
CheckForm2Instance();
form2.DoStuffWithCheckBox();
}
void CheckForm2Instance()
{
if (form2 == null)
{
form2 = new Form2();
form2.FormClosing += form2_FormClosing;
}
form2.Show();
}
void form2_FormClosing(object sender, FormClosingEventArgs e)
{
form2.FormClosing -= form2_FormClosing;
form2 = null;
}
}
using System.Windows.Forms;
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
CheckedListBox checkedListBox = new CheckedListBox();
Controls.Add(checkedListBox);
checkedListBox.Items.AddRange(new object[] { "A", "B", "C" });
}
public void DoStuffWithCheckBox()
{
MessageBox.Show("Doing Stuff");
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Dave that worked I modified just a bit of the code and it worked out.
Thanks
|
|
|
|
|
Hi there i'm trying to read data from SQL
This is my Class
class Sql
{
public SqlConnection sqlCon;
public void connectToSql (string adr)
{
sqlCon = new SqlConnection(adr);
try
{
sqlCon.Open();
}
catch (Exception e)
{
string str = e.ToString();
using (StreamWriter sw = new StreamWriter ("out1.txt"))
{
sw.WriteLine (e.ToString());
}
}
}
public void readSql(String col, String tab)
{
try
{
SqlDataReader sqlRead = null;
SqlCommand sqlCmd = new SqlCommand("SELECT * FROM " + tab + " WHERE Column =" + col, sqlCon);
sqlRead = sqlCmd.ExecuteReader();
using (StreamWriter sw = new StreamWriter ("out.txt"))
{
sw.WriteLine(sqlRead.ToString());
}
}
catch (Exception e)
{
using (StreamWriter sw = new StreamWriter ("out.txt"))
{
sw.WriteLine (e.ToString());
}
}
}
public void exitSql()
{
sqlCon.Close();
}
}
}
And this is the error that i get
System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at longliveSorin.functiiSql.Sql.connectToSql(String adr) in D:\work\cte\C#\cifru\longliveSorin\longliveSorin\functiiSql\Sql.cs:line 19
Can someone help me plz
|
|
|
|
|
Could be your connection string, can you post it please
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
private Sql sql = new Sql();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
String adr = @"Address=localhost;Initial Catalog=Cifru;connection timeout=10;";
sql.connectToSql(adr);
sql.readSql("NumePrenume","contacte");
sql.exitSql();
}
I tried it without the @ but it still didn't work
|
|
|
|
|
Looks like your connection syring is all wrong. Take s visit to connectionstrings.com/[^]
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Check if your connection string is correct. You can find all sorts of connection strings here[^].
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Thank you i'll take a look
|
|
|
|
|
Hi,
There is a compiler switch to create pdb symbols in VC++. What needs to be done to create symbols for a C# app?
I couldn't find any setting in the project properties page. I have noticed that when I compile the project, it creates a pdb in
the debug/release folder.
MSDN says we can use csc /debug /pdb:tt t.cs to create PDB, but is there a way to create PDBs from the GUI?
Thanks in advance,
Nachiket
|
|
|
|
|
Yes, by compiling your code.
The file maps the binary back to the source-code, and is as such, dependent on the binary. Without the binary there is nothing to map.
|
|
|
|
|
Thanks Eddy.
So what kind of symbols are created when I compile the code? public or private?
I am looking for a way to create private symbols so that I can see source file and line number information from a crash dump through windbg.
|
|
|
|
|
I just copy them to the bin\debug-directory. You might be interested in this[^] article.
I are Troll
|
|
|
|
|
|
You're welcome
I are Troll
|
|
|
|
|
Hi all,
I know this is not a C# relating question, didn't found a better forum .... but I read
so much and I tried much more...
The problem: I compiled a .chm helpfile with a correct linked html-file-site structur.
Outside the .chm file everything works fine.
I used different tools and I came always to the same result - the contens side stays blank
(than means - the typical message ... there is no internet connection ....comes up)
I registered the .chm file in the registry and controled that.
I set the correct accesslevel in the registry to Nr. 2 (means that local rights are accepted)
I decompiled my .chm file to see that the html-files are realy included - all seems to be fine.
What more is to do that the .chm contens will be shown ???
Thanks
Regards,
Frank
|
|
|
|
|
I've seen issues like that crop up due to Privacy Settings in the Internet Options. Try adjusting those to be less restrictive and see what happens.
You might also try making sure your CHM is on your local computer's hard drive rather than on a networked drive. Just a few things to check out.
|
|
|
|
|
Thank's for your suggestions,
the .chm file was generated on the local computer and shall be opened there also.
Thanks
Regards, Frank
|
|
|
|
|
You say you have tried lots, so it is difficult to know what to suggest.
However I have had this problem a few times and it has always been #2 from this[^] that has caused my problems. If you haven't already done so can I suggest that you google for problem with chm file blank contents, there are lots of hits.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi Henry,
there are realy some more suggestions to solve the problem. I will follow your links. Will see what will happen.
But i fear I can't deploy a .chm file with my application due to similar expected problems on the clients.
Isn't there a more reliable (local) help technology on the market than .chm ?
Thanks,
Regards, Frank
|
|
|
|
|
Hi,
I am using Windbg to analyze a crash that was created from managed code. I am loading SOS and mscorwks and using the !pe command. I can see the managed callstack, with module and function names but no source file and line number information. I can see this information for native crashes, but not for managed.
I don't know if it is the PDBs or something else. when I did lm, it says I have private pdb symbols for my managed app.
Any help is highly appreciated.
Thanks
Nachiket
|
|
|
|
|
All,
I am interested in developing servers like FTP, HTTP/HTTPS using Windows XP with IIS 5.1 version server. I have searched a lot on internet for pointers which will give me information for creating all these servers using C#, but everything went vain! . I would request this forums members to give some information on implementing all these 3 servers using C#.I appreciate your help
Thanks Rajesh
|
|
|
|