|
Hi guys, I want to know that what if I dervied a class from a Control class and this custom class can have many other controls about 30 controls like image, button, textfields, etc. So if i dispose the custom class object does it dispose all the inner controls as well. or Do I need to implements dispose method from IDisposable interface and then dispose each of the inner controls.
public class customClass:Control
{
}
or
public class customClass:Control,IDisposable
{
}
|
|
|
|
|
As the Control class implements IDisposable , you just need to override the void Dispose(bool) method. Call base.Dispose() to make sure the control classes dispose is also getting called.
|
|
|
|
|
thanks for replying, but when i write like
protected override void Dispose(bool disposing)
{
}
i don't get the Dispose function name from the list i am using VS2005 framework 2.0
|
|
|
|
|
Take a look at this article[^].
If any of the base classes in your inheritance chain implements the IDisposable interface, overrides void Dispose() , or overrides Finalize , you should simply override Dispose(bool disposing) , adding your cleanup logic and making sure to call base.Dispose(disposing) as the last statement.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
i'm trying on sending the server public key to the client by using an xml file.i want to know how retreive the public key from the xml file in client progrm.
|
|
|
|
|
Hi,
I have a DataTable bound to a DataGridView with this code:
dataGridView1.DataSource = myDT_Items;
I'm updating a DataGridView with this code:
dgvRow.Cells["ItemSize"].Value = 55;
Now I want the DataTable to reflect the changes made to the DataGridView. Currently I'm using:
myDT_Items.AcceptChanges();
Q: Is there another way to Synchronize DataTable with DataGridView when changes are made to the DataGridView?
Thanks,
Ron
|
|
|
|
|
Why are you using the synchronization? Are you using datagridview some where else as well?
If not then do the changes directly in the datatable.
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
Thanks Ahsan,
Yes, I could update the DataTable directly, but then I'd have use something like dataTable.Rows.Find() to correlate with the selected row in DataGridView. Do you know of a better way to find the DataTable row based on the selected DataGridView Row?
Even if I do go the route of updating the DataTable directly, I'm always interested in learning more. I'm basically wanting to know the best way to sync the DataTable with the DataGridView if the DataGridView is edited.
Ron
|
|
|
|
|
How can i create my own shortcut key with ctrl+y for saving file in ms visio using c# .net.
tahir
|
|
|
|
|
using System;
using System.Reflection;
namespace SqlSentence
{
public static class SqlString
{
public static string SELECT(this string This, params string[] columnName)
{
string s=" SELECT ";
for (int i = 0; i < columnName.Length; i++)
{
s += columnName[i] + ",";
}
return This + s.Substring(0, s.Length - 1);
}
public static string FROM(this string This, string tableName)
{
return This + " FROM " + tableName;
}
public static string AS(this string This, string target)
{
return This + " AS " + target;
}
public static string WHERE(this string This, string term)
{
return This + " WHERE " + term;
}
public static string EQUAL(this string This, string value)
{
return This + " = " + value;
}
public static string EQUAL(this string This)
{
return This + " = ";
}
public static string PARAMETERS(this string This, string value)
{
return This + "@" + value;
}
public static string AND(this string This, string where)
{
return This + " AND " + where;
}
}
}
using System;
using System.Windows.Forms;
using System.Data.SqlClient;
using SqlSentence;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = cmd.CommandText.SELECT("Name",
"sex".AS("Sex") , "ID").
FROM("customer").WHERE("name".EQUAL
("'zhangshan'").AND("sex".EQUAL
("'boy'")));
SqlCommand otherCmd = new SqlCommand();
otherCmd.CommandText = otherCmd.CommandText.
SELECT("name",
"sex".AS("Sex"),
"ID").
FROM("customer").
WHERE("name".EQUAL
("'zhangshan'").AND
("name".EQUAL().
PARAMETERS("value")));
}
}
}
|
|
|
|
|
Your code would be clearer if you simply wrote out the query; I don't think you gain anything by this technique.
@"
SELECT name
,sex AS Sex
,ID
FROM customer
WHERE name='zhangshan'
AND sex='boy'
"
And I don't see where you're adding the parameter in the second example.
|
|
|
|
|
I don't think is clearer like that
|
|
|
|
|
Good for you. Unfortunately the rest of us do NOT share the same enthusiasm as you
|
|
|
|
|
No, that's not like LINQ at all.
Slightly interresting attempt at building queries in a structured way using expansion, but it needs a lot more to be anything other than restricting. How about joins, grouping, sorting, subqueries, functions, operators...?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi,
Is it possible to select and expand a treeNode in a treeView by program, with the treeNode highlighted ? I tried many methods, but none can get the treeNode highlighted while it expand ! I want to emulate the situation where user click the treeNode by program.
Thanks
Kim
|
|
|
|
|
You can do it by using SelecedNode.
example :
TreeView1.SelecedNode = TreeView1.Nodes[0].Nodes[4].Nodes[20];<br />
TreeView1.Focus();
Hello Friends
|
|
|
|
|
It works !
Thanks so much
|
|
|
|
|
You`re welcome
Hello Friends
|
|
|
|
|
Hi,
I just find a problem in getting the treeNode selected and highlighted if the treeView is in a panel rather than in the form directly, the treeNode cannot get the focus. I try to focus the panel also, but it didnt help.
Thanks
|
|
|
|
|
like this:
void print <T, G, F,...>(T t, G g, F f, ...);
print <int, string, double,...>(10, "hello", 10.01,...);
thanks!
|
|
|
|
|
What happened when you tried it ?
|
|
|
|
|
I am trying to insert a new record into my database. The primary key field is an integer. How can I determine what the max value for the field is before I do my insert?
I know this is very easy if I put the insert inside of a stored proc and just do a Max() before my insert, but for this project I can not use stored procs, all the sql is in the code. Also, I know I can set the primary key to be an identity field, but I am trying to avoid that.
Here is my current code:
public bool Insert(ActionObject obj)
{
SqlCommand sp;
try
{
using (SqlConnection conn = SqlConn)
{
conn.Open();
string sql = @"INSERT
INTO [dbo].[Action] ([ActionId], [ActionName], [ActionDescription])
Values (@ActionId, @ActionName, @ActionDescription)";
sp = new SqlCommand(sql, conn);
sp.CommandType = CommandType.Text;
sp.Parameters.Add("@ActionId", SqlDbType.Int).Value = obj.ActionId;
sp.Parameters.Add("@ActionName", SqlDbType.VarChar).Value = obj.ActionName == null ? "" : obj.ActionName;
sp.Parameters.Add("@ActionDescription", SqlDbType.VarChar).Value = obj.ActionDescription == null ? "" : obj.ActionDescription;
sp.ExecuteNonQuery();
}
}
catch(Exception)
{
throw;
}
}
|
|
|
|
|
If you make the primary key column an identity column then SQL Server will work it out for you. That way you don't have to calculate it in advance - and run the risk of someone else performing the same calculation and getting in there before you.
|
|
|
|
|
I agree that would be the best solution, unfortunately these tables are already created and I can not alter their structure.
|
|
|
|
|
Then to do it safely you need to use a transaction. Have a look at the SqlTransaction class.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|