|
Hi guys,
I have two checkboxes on my datagrid and I have an event that fires whenever the first checkbox is checked (code follows)... but I don't know how to figure out where (what index) the checkbox that fired the event is coming from!!! Please Help!!!
private void cb_CheckedChanged(object sender, EventArgs e)
{
bool bIsChecked;
CheckBox cbTemp = (CheckBox) sender;
bIsChecked = cbTemp.Checked;
if (bIsChecked && ((CheckBox)this.Items[THE INDEX OF THE SENDER!].Cells[1].Controls[0]).Checked)
((CheckBox)this.Items[THE INDEX OF THE SENDER!].Cells[1].Controls[0]).Checked = false;
}
Thanks in advance to anyone who helps me out!
|
|
|
|
|
Set the IDs of the checkboxes as you create them, or in databinding, or something.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
i'm trying to get my C# application to connect to a database which is located in another computer.
what are the steps required to make it function?
i have installed odbc .net data provider and i've tried using this connection string:
myConnectionString = "DRIVER={SQL Server};SERVER=localhost;UID=rfid; Trusted_connection=true;DATABASE=rfid;";
but it gives me a error of access denied or server doesn't exist, i'm not so clear about this, thus i hope to know what are all the steps required for both the client and server to do inorder to make this work
thanks!
-----------------------------------------------
BingLin
|
|
|
|
|
Try changing your SERVER name from localhost to the actual name of the server machine. To get the machine name, right click on "My Computer" and select properties. Select the "Computer Name" tab and you will see the "Full Computer Name".
Hope this helps
Craig
|
|
|
|
|
i've tried connecting to a database in my own computer first, and this is my codes for the connection to test:
string myInsertQuery = "INSERT INTO test (id) Values(4)";
myConnectionString = "DRIVER={SQL Server};SERVER=localhost;UID=root; PWD=wq;Trusted_connection=true;DATABASE=rfid;";
OdbcConnection myConn = new OdbcConnection(myConnectionString);
OdbcCommand myOdbcCommand = new OdbcCommand(myInsertQuery);
myOdbcCommand.Connection = myConn;
myConn.Open();
myOdbcCommand.ExecuteNonQuery();
myConn.Close();
my userid is root, password is wq and database name is rfid, but still it gives me back a result of server doesn't exist or access is denied. is there anything wrong?
|
|
|
|
|
Are you using SQL Server database ?
If you are using SQL Server then you should use SqlConnection and SqlCommnad as follows.
string myInsertQuery = "INSERT INTO test (id) Values(4)";
myConnectionString = "Initial Catalog=rfid;Data Source=localhost;UID=root;PWD=wq"
//Build a SQL Connection
SqlConnection myConn = new SqlConnection(myConnectionString);
//Create a command
SqlCommand cmd = new SqlCommand(myInsertQuery,myConn);
myConn.Open();
cmd.ExecuteNonQuery();
myConn.Close();
myConn.Dispose();
|
|
|
|
|
i tried using the connection string u gave, but it gave me an error:
Data source name not found and no default driver specified
i'm using mySQL server 4.1, and sharpdevelop for my application
my database is in C:\Program Files\MySQL\MySQL Server 4.1\data\rfid
i can't find the error, is there any places with sample programs which i may refer to?
|
|
|
|
|
|
I have a bit of code which declares local variables in a loop, to perform intermediate calculations.
The issue is: the local variable declarations came naturally, as the thought process in designing the loop, but they could be criticised for putting 2 variables on the stack with each loop iteration, so, in the interests of efficiency, they should be declared outside the loop. However, I wonder if it would be better to leave the natural sequence, and trust the compiler to optimise.
The section of code is similar too...
System.DateTime startTime = System.DateTime.Now;
int step = 0;
while (true)
{
System.DateTime now = System.DateTime.Now;
System.TimeSpan span = now - startTime;
if (span.TotalMilliseconds >= step * 1000)
{
System.Console.WriteLine("Tick {0}",step);
step++;
}
}
Stephen Hosking
|
|
|
|
|
I'd do it right myself, and then not have to worry. And I wouldn't bother to declare a variable called 'now'.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
>> And I wouldn't bother to declare a variable called 'now'.
lol! Quite right. The example was slightly contrived from the original, where the variable was justified, because it was used in several places.
|
|
|
|
|
I absolutely would never do this kind of optimization.
Yes, always trust the compiler. Only optimize algorithms - that's the way I do it and it saves quite a bit of worrying
|
|
|
|
|
The stack frame does not change when you declare variables. The stack frame is created when the method is called, and allocates space for all variables used in the method.
The only difference if you move the declaration is that the scope of the variables change. The space for the variables is still allocated the same way.
I always keep the declaration of the variables separate from the code. This is a practice that I got from Pascal programming. (In Pascal the variable declaration is even placed outside the actual procedure body.) I think that it makes the code clearer, and it actually more closely resembles what is actually happening when the code is executed.
---
b { font-weight: normal; }
|
|
|
|
|
I have drawn a Rectangle and corresponding X and Y axes with tick marks.
I would now like to number the tick marks on each tick in the range of
-9 to +9. Not sure of an efficient way to attack the problem. Any ideas?
many thanks...;)
|
|
|
|
|
A forloop and DrawString, I would have thought...
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm writting an app that I hope to sell and develope into an enterprise type app. It came to my attention that I should have all my data access in a DAL along with my business objects. So my question is at what point is it necessary to implement a DAL and business object layer as to just writting a class for data access and keeping your business objects in your main app class?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Tom Wright wrote:
So my question is at what point is it necessary to implement a DAL and business object layer as to just writting a class for data access and keeping your business objects in your main app class?
Now. You should always do your business tier in a seperate dll, and your data access in another seperate dll. The reason is simple, it forces you to keep these layers seperate, which makes it easier to replace any layer if you ever need to, and to encapsulate your code in logical components.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
I was hoping you could help me with a problem I'm having. I am writing a .DLL that reorders and renames a folder of images using System.Drawing.Image and System.IO. The .DLL is called from a Windows form, which catches events as the .DLL processes each file. I'd like the Windows application to show the image that is currently being processd.
My solution has been to create an event that is triggered as each new image is identified, passing the image out. I cannot just pass out the actual image, as the calling application's picture box would lock the image so it couldn't be moved etc by the .DLL.
What I have done instead is to redraw the image as a smaller bitmap (to the dimensions of the picturebox), this works in as much as it doesn't lock the file, but the picture box is blank (though there is a bitmap being passed, according to the Auto dialog).
I've checked my bitmap code in a seperate application that doesn't rely on an external .DLL and it works.
I've successfully passed strings and integers out, that have then appeared in the appication.
I'd like to know if I'm doing this the best way and where I am going wrong, cheers!
Bitmap conversion code in .DLL, DoNextFile is the trigger.
System.Drawing.Image img = System.Drawing.Image.FromFile(sour_file);<br />
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(144, 108);<br />
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);<br />
g.DrawImage(img, 0, 0, 144, 108);<br />
<br />
DoNextFile(bmp);
Creation of the Trigger in .DLL
public delegate void NextFile (System.Drawing.Image img);<br />
public event NextFile Next;<br />
<br />
private void DoNextFile(System.Drawing.Image img)<br />
{<br />
if (Next!=null)<br />
Next(img);<br />
}
Catch code in Windows app.
public void CatchNextFile (System.Drawing.Image img)<br />
{<br />
if (pbxFile != null)<br />
{<br />
pbxFile.Dispose();<br />
}<br />
pbxFile.Image = img;<br />
this.Update();<br />
}
|
|
|
|
|
Well, you are Disposing of the picturebox... perhaps you meant pbxFile.Image.Dispose()?
|
|
|
|
|
If it's that easy I'm not sure but I might cry...
|
|
|
|
|
Thank you for your help, I can't believe I made such a mistake.
Thanks again.
|
|
|
|
|
I'm reading text data from an xml file where there are potential newlines embedded into the string, but in some places I need to display the full text on a single line. Whenever I doso however I get to of the empty blocks used as placeholders for unprintable chars.
The xml data looks like this:
<comment>line one
line two</comment>
after reading it into a string (indirectly using the xml classes (we're using encapsulated versions that hide the ugly details)) I've tried both of the following unsuccessfully to remove the newlines.
s.Replace("\n"," ");
s.Replace(Environment.NewLine," ");
|
|
|
|
|
Strings are immutable
s = s.Replace(Environment.NewLine, "");
|
|
|
|
|
Woops, I knew that. :-/
Would've been nice if the compiler gave a warning though.
|
|
|
|
|
Hi everyone,
Is there an event like Form.Resize that is raised only after the user has finished resizing the form, i.e., when the mouse button is released at the end of the resize operation?
Thanks
|
|
|
|