|
Or just unplug them!
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Why not just provide a delegate and event that can be registered when the second form is created, and hook in an event handler on the first form before you show the second form.
[EDIT] What happened to my thread, the forum must not have liked my response! [/EDIT]
- Nick Parker My Blog | My Articles
|
|
|
|
|
|
Heath Stewart wrote:
You could do that, but it seems like an aweful lot to do for something as simple as passing a reference to your ListView or just getting the database from the second form to put into your first, kind of like an InputBox of yesteryear.
Figures you wouldn't totally agree with something I said!
- Nick Parker My Blog | My Articles
|
|
|
|
|
That's not it at all.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
I'm trying what you said, but i don't know how to pass a reference to another form. Is there an article i can read, or can you give me quick example of how to do it. Sorry, i'm still a beginner with programming.
thxs for the advice you gave.
|
|
|
|
|
Why I personally perfer having the second form just return the data as a property or something, passing a reference to the first form isn't hard at all. Here's an example:
public class FirstForm : Form
{
private void btnSecondForm_Click(object sender, EventArgs e)
{
using (SecondForm form = new SecondForm(this))
{
form.ShowDialog(this);
}
}
internal ListView TheListView
{
get { return theListView; }
}
}
internal class SecondForm : Form
{
private FirstForm parent;
public SecondForm(FirstForm parent)
{
this.parent = parent;
}
private void btnOK_Click(object sender, EventArgs e)
{
ListView view = parent.TheListView;
if (view != null)
{
this.DialogResult = DialogResult.OK;
}
}
} As you can see, though, not SecondForm is tightly coupled with FirstForm , which is why simply having the SecondForm define a property which returns the input data would be better, because then you could use it anywhere when you need to query for such data.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
Can someone pls tell me, if its possible to change the permissions of a registrykey using C#.
Searching the web, all I found is to read/create/write... keys and values, but the often asked question to give a userthe right to read/execute is never answerd.
(to be more specific: I used aspnet_setreg.exe to create registrykeys. In my Web.config I use the identity-tag. The only way to give the ASPNET Machine Account the right to read the keys I found is using regedit / Context-Menü and add the account manually)
thx for replies
Sebastian
|
|
|
|
|
Yes, it is possible, but you must P/Invoke a lot of native APIs in order to do so. It's definitely not an easy task. If this isn't something you need to do often or automate, don't bother.
If you need to, see the RegSetKeySecurity API in the Platform SDK on MSDN[^]. There's also examples available that use this and related APIs. You'll need to P/Invoke all these methods, as well as declare all the structs and consts necessary to set security on registry keys.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you for the reply. I feared a solution like this, but now I know which way to go.
Sebastian
|
|
|
|
|
Hello,
I have a simple xml-file and i show it in a datagrid like this:
ds.ReadXml(@"c:\nodes.xml");
But one of the colums is true/false. So i would like a column with checkboxes in my datagrid. I found something about the DataGridBoolColumn but i can't make it work. Is it possible or is their another way?
thx in advance.
|
|
|
|
|
Why can't you make it work? Please be specific.
All you need to do is add it to your DataGrid<code> and bind it to your column by setting the <codE>MappingName as you would with a DataGridTextBoxColumn .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'll try to explain it.
ds.ReadXml(@"c:\testnodes.xml");
dataGrid1.DataSource = ds;
dataGrid1.DataMember = "library";
GridColumnStylesCollection myGridColumnCol;
myGridColumnCol = dataGrid1.TableStyles[0].GridColumnStyles;
// Get the CurrencyManager for the table.
CurrencyManager myCurrencyManager =
(CurrencyManager)this.BindingContext[ds.Tables["library"]];
/* Get the PropertyDescriptor for the DataColumn of the new column.
The column should contain a Boolean value. */
PropertyDescriptor pd = myCurrencyManager.
GetItemProperties()["super"];
DataGridColumnStyle myColumn = new DataGridBoolColumn(pd);
myColumn.MappingName = "super";
myGridColumnCol.Add(myColumn);
this is code i found on the internet, in the datagrid i can see the data but just text, no column has checkboxes.
the xml-file looks like this:
<sessie name="bedrijf">
<libraries>
<library name="comlib">
<fullname>comlib.p</fullname>
<super>true</super>
<loadorder>4</loadorder>
</library>
<library name="templateinqlib">
<fullname>templateinqlib.p</fullname>
<super>true</super>
<loadorder>5</loadorder>
</library>
<library name="Librarytest">
<fullname>Test</fullname>
<super>false</super>
<loadorder>5</loadorder>
</library>
</sessie>
thx in advance
|
|
|
|
|
That's a bad example if I ever saw one. First, they don't set a DataGridTableStyle.MappingName so that the table style would never be used. Second, you just manually add your DataGridColumnStyle s to the table style you set up. If you use a typed DataSet , VS.NET has great designers to help you bind against it, though it's not hard to do anyway. This is most likely why you're not seeing your DataGridBoolColumn - because the table style isn't even being used.
Read the documentation for the DataGridTableStyle class, which includes more information and an example.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thx for helping me and is was indeed a bad example
ds.ReadXml(@"c:\testnodes.xml");<br />
dataGrid1.DataSource = ds;<br />
dataGrid1.DataMember = "library";<br />
<br />
DataGridTableStyle ts1 = new DataGridTableStyle();<br />
ts1.MappingName = "library";<br />
DataGridColumnStyle Col = new DataGridTextBoxColumn();<br />
Col.MappingName = "fullname";<br />
Col.HeaderText = "IsCurrent Customer";<br />
Col.Width = 150;<br />
ts1.GridColumnStyles.Add(Col);<br />
<br />
DataGridColumnStyle boolCol = new DataGridBoolColumn();<br />
boolCol.MappingName = "super";<br />
boolCol.HeaderText = "IsCurrent Customer";<br />
boolCol.Width = 150;<br />
ts1.GridColumnStyles.Add(boolCol);<br />
<br />
DataGridColumnStyle TextCol = new DataGridTextBoxColumn();<br />
TextCol.MappingName = "loadorder";<br />
TextCol.HeaderText = "Customer Name";<br />
TextCol.Width = 250;<br />
ts1.GridColumnStyles.Add(TextCol);<br />
<br />
dataGrid1.TableStyles.Add(ts1);
i followed your advice and tried it on my application and it worked. But i'm still forgetting something. I can see checkboxes in my datagrid now but they are all checked (in grey) although in my xml-file some are false. I can click them but they change back immediately when i leave a cell which is not good because when it's changed it has to change in the xml-file too.
hope you understand what i mean and thx again
|
|
|
|
|
Don't declare your variables as the base class (i.e., DataGridColumnStyle ) so that you can easily access the FalseValue and TrueValue properties and set them accordingly. You can still just pass those variables into GridColumnStyles.Add because they are still DataGridColumnStyle instances (since it's their base class).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i'm sorry but i don't really understand what you mean? Don't i have to declare the variables?
|
|
|
|
|
Yes, but don't declare them as DataGridColumnStyle otherwise you have to cast them to access the properties. Just declare them as the types you're instantiating:
DataGridBoolColumn col1 = new DataGridBoolColumn();
DataGridTextBoxColumn col2 = new DataGridTextBoxColumn();
tableStyle.GridColumnStyles.Add(col1);
tableStyle.GridColumnStyles.Add(col2);
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
oh ok i understand. I also found an example of it in the MSDN, i do exactly the same and the name of my table and column are correct too.
He says there is a mistake in this line
boolCol = (DataGridBoolColumn) dataGrid.TableStyles["library"].GridColumnStyles["super"];
:
An unhandled exception of type 'System.NullReferenceException' occurred in Test.exe
Additional information: Object reference not set to an instance of an object.
Do you know what could be wrong?
DataGridBoolColumn boolCol = new DataGridBoolColumn();
boolCol = (DataGridBoolColumn) dataGrid.TableStyles["library"].GridColumnStyles["super"];
boolCol.MappingName = "super";
boolCol.TrueValue = true;
boolCol.FalseValue = false;
boolCol.Width = 150;
ts1.GridColumnStyles.Add(boolCol);
|
|
|
|
|
Yeah, you can't reference a column before it's added to the table style! Remove the second line in your code sample. I don't know why you added it in the first place. You're already instantiating boolCol , so why are you (incorrectly) trying to get it then from the table styles - which you haven't added the column to yet?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i made a little mistake while typing, it had to be :
DataGridBoolColumn boolCol; and not " = new DataGridBoolColumn "
boolCol = (DataGridBoolColumn) dataGrid.TableStyles["library"].GridColumnStyles["super"];
boolCol.MappingName = "super";
boolCol.TrueValue = true;
boolCol.FalseValue = false;
boolCol.Width = 150;
ts1.GridColumnStyles.Add(boolCol);
But if i remove the second line as you said it still doesn't work
then it's the same as it was before, de checkboxes are grey and you can't change them.
|
|
|
|
|
Again, you can't reference the column until it's actually added. You want DataGridBoolColumn boolCol = new DataGridBoolColumn(); .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
ok thx a lot!
another problem i just encountered was
boolCol.TrueValue = true;
should be:
boolCol.TrueValue = "true";
so now he does change the checkboxes
|
|
|
|
|
Of course, because both TrueValue and FalseValue (which you should also set) are string properties.
Microsoft MVP, Visual C#
My Articles
|
|
|
|