Thanks a lot!
6 921 364 and growing
Posts
-
A question about references -
A question about referencesRon, I was thinking upon Ian's answer and finally understood the concept. You may like to check my reply to Ian. Thanks for your help. Since your answer is also correct, I am voting it up. :thumbsup:
-
A question about referencesThanks, that very much clears the doubt. Please see what I got is correct: I have a reference stored to the object of the
TestClass
on the stack. When I pass this to the methodChangeClass
, I just pass a value which refers to a memory location which is same as the actual memory location of the object. So any change to the fields of the class is reflected as the method is accessing the same memory location. When I assign the object null in the method, the reference to the object is no more available to the method. But it is still available to the Main method. This is my understanding. Please let me know if I am wrong somewhere. Thanks and voted as a "good answer". PS: I am changing the message type to answer as it contains descriptive answer. -
A question about referencesThank you for answering.
Rob Philpott wrote:
That's because tc is a reference type passed by value, ie. a local copy
I do understand that, but what confuses me is why the values are changed then. I see an inconsistency in the behaviour. Since the memory reference is passed, if we are changing the value in the method, it is getting changed and assigning a null doesn't.
Rob Philpott wrote:
Stick the word 'ref' in front of it and you'll probably get the behaviour you're expecting.
Yes that will do the job.
-
Cancel CellValidating error in DataGridView, so can close form while invalid entry still presentThanks for replying. I saw no one replied but thought you may have devised a work around. The behaviour isn't good. Close button is close button afterall. Anyways thanks for your time. Cheers!
-
A question about referencesIn C# - Classes are reference types; structures are value types. I was reading about this and saw something which I didn't understand. I have created a simple program to explain my doubt. In this program I have defined a class and a structure with an integer variable.
class TestClass
{
public int x;
}
struct TestStruct
{
public int x;
}Now I have couple of static methods each changing the value of the integer.
static void ChangeStruct(TestStruct ts)
{
ts.x = 10;
}
static void ChangeClass(TestClass tc)
{
tc.x = 10;
//tc = null;
}Now in the main method, I call this functions and results are as expected.
static void Main(string[] args)
{
TestStruct ts = new TestStruct();
ts.x = 20;
Console.WriteLine("Before change: ts is ({0})", ts.x);
ChangeStructure(ts);
Console.WriteLine("After method: ts is ({0)", ts.x);
TestClass tc = new TestClass();
tc.x = 20;
Console.WriteLine("Before method: tc is ({0})", tc.x);
ChangeClass(tc);
Console.WriteLine("After method: tc is ({0})", tc.x);
Console.ReadLine();
}So far so good. Now when I uncomment the line
tc = null;
in the methodChangeClass
, I expect the class to be null referenced i.e it should not reference to any memory in the heap any more. But that is not how it works. Can anybody explain me why there is a different behaviour here. Thanks a lot! -
Cancel CellValidating error in DataGridView, so can close form while invalid entry still presentI know it's pretty old but I faced the same problem and wanted to ask if you managed solve it or not? Even setting CausesValidation property of the close button doesn't work. What have you done to work around the issue? Thanks a lot.
-
Bulk updating values from GridView bound to a datatable [moved]I finally got that working. It was simple as I expected just that I didn't put much effort. This is what I did: User does the required edits (unchecking the checkbox for not received and editing the exact received quantity) an select 'Save'. On Save button click, I get the old data which was saved in ViewState into a datatable. Now I compare the GridView values to the values in DataTale (old values). If it has changed, I edit the value in the datatable. This changes the
RowState
of that row in the datatable. The code seems like this:DataTable dtChallanDtl = new DataTable();
dtChallanDtl = (DataTable)ViewState["ChallanDtl"];
int i = 0;
int ChallanRcvd = 1;
foreach (GridViewRow r in gvChallanDtl.Rows)
{
CheckBox chk = (CheckBox)r.FindControl("CheckSelect");
TextBox txt = (TextBox)r.FindControl("txtRecvQty");
if (chk.Checked == true)
{
dtChallanDtl.Rows[i]["Received"] = 1;
}
else
{
ChallanRcvd = 2;
}
if (dtChallanDtl.Rows[i]["RecvQty"].ToString() != txt.Text)
{
dtChallanDtl.Rows[i]["RecvQty"] = txt.Text;
dtChallanDtl.Rows[i]["Received"] = 2;
ChallanRcvd = 2;
}
i++;
}Here, the variable 'ChallanRcvd' represents the database column which stores the received status of the challan. 0-not received, 1-received, 2-partailly received. Now I do a bulk update using
SqlDataAdapter's Update
method. The important things here are: SqlDataAdapterObj.UpdateBatchSize = 4; //how many records need to be updated in each batch. SqlCommandObj.UpdatedRowSource = UpdateRowSource.None; //how command results are applied to the datarow. After all parameters are supplied, callSqlDataAdapterObj.Update(dtChallanDtl);
I posted this question here because I couldn't find any example on bulk edit using GridView bound to a datatable. I hope it helps someone. Regards Test -
Bulk updating values from GridView bound to a datatable [moved]I feel it may require threaded discussion so I am moving the question here from Q&A. Greetings everyone! This may be a very simple question but I just can't get it working. Moreover Google doesn't seem to help me much (Or I still have a lot to improve on my searching skills. :) ) Let me explain the scenario: This page is basically accessed by a user who has received some items and has to update this page accordingly. I have a GridView bound to a DataTable. The GridView has a checkbox column, few databound columns and a TemplateColumn with a TextBox as ItemTemplate. The GridView has to be updated with two things - a) By unchecking a checkbox, the user indicates that the particular item has not been received. So a flag indicating unreceived will be marked in the database. b) The textbox in the template field will by default contain quantity sent for that particular item. The user can update it to actual quantity received. After all edits are done, user clicks the save button and details (a) and (b) has to be updated to the database at a time. What I have tried: I save the initial GridView value in a ViewState. When the user clicks 'Save' I thought I will get the DataSource and compare the values and do a bulk update using a DataAdapter. But the DataSource is null (which is correct). I do not seem to be able to use things like DataTable.RowState for bulk update. How do I synchronize the GridView with the bound DataTable? Please help me on how should I go about it. Thanks!
-
Back to login pageIf you mean user should not be able to go back to the page they logged out from, yes, this is very much possible. I would like to inform you that this is asked here so many times. So do a CodeProject search[^] and you will get a lot of hits. I will give you a hint. Search for "disable back button" or just "disable back" for more results (select only question and answer check box to get results from Question and Answers). See if that helps you. If you still don't understand, get back and explain your problem.
-
Latest Message From Space [modified]sir i m vry sry! :-D
-
Latest Message From Space [modified] -
Attachment in Q&AYeah. Quite possible.
-
Is Cincin a girl's name?I wished she would. ;P Her friend finally let us knew.. :-D
-
Is Cincin a girl's name?Pete O'Hanlon wrote:
Are you having doubts about whether you are a boy or a girl?
I think his/her friends have. :laugh: I remember we had a guy/girl in our college from Malaysia. We didn't knew his/her gender till the last day of the college. ;P