|
You don't have it bound to a data column correctly. The default value only applies when the data the column is bound to doesn't already have a value. Likewise, if it's not bound correctly it always appears checked.
Read the documentation for the DataGrid.DataSource and DataGrid.DataMember properties about binding data - any IList or IListSource implementation like a DataSet or DataTable - to the DataGrid , as well as the DataGrid.TableStyles about how to apply table styles to a particular data source.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath,
thanks for your advice but i have already bound the DataGrid to a DataSet
dataSAR.DataSource = gmb.gmbSet;
dataSAR.DataMember = "SAR";
Then i set up a DataGridTableStyle , mapped it to the table.
DataGridTableStyle sarStyle = new DataGridTableStyle();<br />
sarStyle.MappingName = "SAR";
Next i created a DataGridBoolColumn object and mapped it to the corresponding column in the table
DataGridBoolColumn checkColumn = new DataGridBoolColumn();<br />
checkColumn.MappingName = "Checked";
Finally i added the column to the TableStyle and added the TableStyle to the DataGrid.TableStyles collection.
sarStyle.GridColumnStyles.Add(checkColumn);<br />
dataSAR.TableStyles.Add(sarStyle);
I think that this is the correct way of going about this but i am having the problems mentioned in the above post so any advice about what i am doing wrong would be appreciated.
Cheers
KP
|
|
|
|
|
Make sure the TrueValue and FalseValue properties are set to whatever you use for true and false values. These values are case-sensitive.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How would that affect me checking / unchecking the check box at runtime? When i uncheck the box at runtime, as soon as the focus goes to another part of the form the box is checked again.
KP
|
|
|
|
|
It's called data-binding. Controls are bound to data, which is updated when the control is changed and vice versa. If the true/false values are not the same for both, the value can't be bound.
Read the class documentation for the DataGridBoolColumn in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath,
I have set the default true/false values for the DataGridBoolColumn to lower case true and false so that they match with the Value applied when a check box is checked / unchecked and it appears to work.
Thanks for all your help, i really don't think i would have figured this one out by myself.
KP
|
|
|
|
|
Hi all,
I have seen lots of articles on the subject of datagrid controls and check boxes. I am currently designing a goods movement system for the company i work for and i have most of it finished. However, on the last page i want to display a datagrid control with data that has been entered on previous pages, that bit i have done including formatting the datagrid (which took some figuring out but i got there in the end).
The user will have to go through each entry every week and tick them off one by one. I have added a DataGridBoolColumn object to the TableStyle.GridColumnStyles collection and the check box displays fine. However i have 2 problems.
1. The default value for the check boxes is true, i need it to be false and setting the value to false when setting up the column in code doesn't work. Although by answering the next question this might be solved.
2. Whenever i tick/untick the box then move the focus away from the cell in the grid the checkbox returns to a checked state.
any help that you can give me would be appreciated.
Cheers
KP
|
|
|
|
|
i have some questions regarding thread termination. i am giving a user the ability to stop a test case (thread) at any given time. my test cases have tendencies to be in long blocking states (eg, long I/O, or just waiting up to an hour for a certain response). i want the user to be able to abort out of these states. what is the best way? if i carefully clean up everything in the ThreadAbortException catch clause, is it considered OK to explicitly call Thread.Abort on the thread? or should i opt for the passing in of a manualresetevent and checking at the top of the loop, and if in blocked state use thread.interrupt instead?
|
|
|
|
|
Close the resource that the I/O is blocking on. That should unblock the thread and an error condition should also exsist that you can use logically to determine that you need to exit the thread.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
|
my program use treeView control to display as active directory object browser.
it's still fine as i have one treeView control in mainform,but i have problem when i start to include treeView in another form(created from mainform like dialog).
the window almost look not responding when i refresh the second treeView control. i really need help
if you are not clear about what my problem is please let me know
really appreciate the help.
if you have active directory installed, maybe you could help examine my program.
thanks
|
|
|
|
|
|
i download the file, and it's corrupted..what should i do?
|
|
|
|
|
Both files are fine. I download them and unzipped them with no problems. Try downloading them again.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
i can download the file, but when i can't unzip, the report is unknown compression.
maybe you could do me a favor send to my email vcorn8@yahoo.com
Thank you
|
|
|
|
|
Try downloading a free app that can use the .zip extension. Winzip has a free copy (bugs you after 30 days) that can work with Zip files!
Yes, I program in VB, but only to feed my addiction to a warm place to sleep and food to eat!
Visit my Code Project blog (Mobile Audio project)[^]
|
|
|
|
|
Because of restrictions on email where I work, no, I can't.
Besides, I'd be sending you another .ZIP file, more than likely with the same compression, or I'd be sending the same .ZIP file. Do you have WinZip? Then it should work with no problems. Don't rely on the ZIP functionality built into Windows XP and above...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
i have winRAR
it seems it's my internet connection, it took me a while to open codeproject site, i'd be glad if u could send to my mail.
i just wanna know whether he use threading or not.
i found sometimes the work done to active directory is very fast in my program and sometimes run very slow like not responding and i believe it has to do with GUI updating
|
|
|
|
|
Get WinZip. It's worth the trouble to download it. I can't send attachments from work to the outside Internet...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
I am writing a project that runs code from several assemblies.
Each assembly should be isolated, and the project supposes to be lightweight, therefore I am running one process and each assembly runs in a different AppDomain.
The project suppose that an assembly may crash or stack and uses the AppDomain.Unload() method to remove an AppDomain to release its resources.
I got to a problem once I tried to unload an AppDomain while a thread, that belonged to it, was waiting on a MessageQueue.Receive(). The AppDomain threw the CannotUnloadAppDomainException exception and didn't unload, or at least not gracefully.
The problem happens when a thread waits on a message queue and cannot be aborted, interrupted, or terminated forcefully. I didn’t try it, but I believe that the same happens when the thread waits for other things that use internally unmanaged code such as sockets.
How can I unload these AppDomains?
How can I force a thread to exit code that suppose to be managed such as MessageQueue.Receive() and Socket.Receive()?
Thanks,
Ami
|
|
|
|
|
When possible, set Thread.IsBackground to true on threads you create. See the .NET Framework SDK for more information about this property.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
It doesn't work, since the difference between foreground and background threads only affects the way the application exits, and not the way an AppDomain is unloaded.
MSDN: Thread.IsBackground : "A thread is either a background thread or a foreground thread. Background threads are identical to foreground threads, except that background threads do not prevent a process from terminating. Once all foreground threads belonging to a process have terminated, the common language runtime ends the process by invoking Abort on any background threads that are still alive."
What I want to do is to "kill" the AppDomain gracefully, without the need to do anything special within the AppDomain, and changing the way of threads creation is one of them.
I can't believe that I am the first person that gets to this problem. If you can’t “kill” an AppDomain then what is its advantage over a process?
|
|
|
|
|
Ami B. wrote:
I can't believe that I am the first person that gets to this problem. If you can’t “kill” an AppDomain then what is its advantage over a process?
You're probably not - try googling for others.
An AppDomain is an application boundary where assemblies are isolated from each other except through .NET Remoting and proprietary methods (sockets protocols, etc.). ASP.NET uses AppDomains so that when the Web.config file changes, an AppDomain is killed and new one respawned - all from another AppDomain started by the worker process. This allows the process to continue to run and an AppDomain to monitor the change status of the Web.config file so that it can respawn an AppDomain for the ASP.NET web site.
Executing threads must be aborted when the AppDomain needs to be unloaded. This may require changes in the assemblies you're loading, such as spawning threads for I/O, etc., or using async calls.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Very simple example of what I want to do.
I have a textbox on my form:
TextBox textBox1 = new TextBox();
I have a string containing the name of my textbox:
string strControlName = "textBox1";
I have a string that contains the text for my textbox to display:
string strControlText = "Hello World";
How do i use strControlName and strControlText to set my textbox's text property? (without looping through my controls on the form and using if statements).
In another language I know, you can use 'Indirection'. It's a very useful and powerful tool. This acts similar to the following:
set (@strControlName).Text = strControlText
where the end result is textBox1.Text = "Hello World".
I would love to be able to do this in C#! I was told to read up on reflection, but couldn't find what I wanted. Is there somehow a way to modify an existing control when all you know is the control name? (without looping through all the controls) Please help!
|
|
|
|
|
It depends - is the TextBox a field or property declared in your container (i.e., Form , UserControl , etc.) or is it simply a variable? Reflection only works on type metadata, so if it's a variable it won't work.
If it is a field, then you could do something like this:
public void SetText(string name, string text)
{
FieldInfo field = this.GetType().GetField(name);
if (field != null)
{
PropertyInfo prop = field.FieldType.GetProperty("Text");
if (prop != null && prop.CanWrite)
{
object obj = field.GetValue(this);
prop.SetValue(obj, text, null);
}
}
} This also works best when you don't specify the Name properties of controls, which isn't required (the designer does, though).
Microsoft MVP, Visual C#
My Articles
|
|
|
|