|
Even better than an array of strings!
private dictionary<int, string> items = new dictionary<int, string>();
public void save (int id, string value)
{
items[id] = value;
}
-- modified at 14:41 Monday 28th August, 2006
Maybe I should clarify why its better... your "id"s need only be unique with a dictionary, whereas with the string array they would need to be, unique and sequential. Also stuck in a certain range (unless you used an offset).
|
|
|
|
|
I have inserted a datagridviewcheckboxcolumn. But the values of those the checkbox cells are all set to null by default. How do I change them all to "false" which is unchecked?
|
|
|
|
|
Hello
Is your DataGridView databound?? In this case you could just use this line of code to return false to the datasource when the user leaves the value null:
dataGridView1.Columns[0].DefaultCellStyle.DataSourceNullValue = false;
If you still want to initialize the values of the cells, I remember something about default values in DatagridView, but i don't seem to recall it at the moment..
What I can think of now is to handle the RowsAdded and initialize the new cells value to false.
Regards
|
|
|
|
|
Hi
I have set the datagridview.datasource to the defaultview of a datatable. Is it databound then? The thing is that the checkbox column is inserted to the datagridview with null values by default.
The idea is to let the user to check for export. Cos the unchecked boxes are of null values, I've got an error when the null value is accessed.
|
|
|
|
|
Hello
I provided you with two possible solutions in my last post. Are they not suitable??
1- You could ignore the null value and return false to the datasource. This should eleminate the error:
dataGridView1.Columns[0].DefaultCellStyle.DataSourceNullValue = false;
2-Otherwise you could handle the RowsAdded event and set the value of your column for each new row to false
Regards
|
|
|
|
|
Hi
I've tried both but they don't seem to work. It could be that the datagridview is not databound??? For the 2nd solution, it seemed to work initially, but I don't know why the value switched back to null again. I have made the datagridview a global variable, so nothing should have changed the value back.
Now I don't know what to do.
|
|
|
|
|
Hello
printscreen12345 wrote: I don't know why the value switched back to null again.
What??!!
What do you mean switched back again?!! Are you sure you did initialize them to false??
Also, how do you populate your DataGridView if it's not databound?
Regards
|
|
|
|
|
Hi
Yes, I did initialise them to false in the "try" block and they switched back to null in the "finally" block.
I'm not sure if the DataGridView is databound or not. As mentioned in my earlier messsage, I have set dataGridView1.DataSource to a defaultView of a datatable. Is this databound??
|
|
|
|
|
Hello
Yes this is databound, as long as your DataGridView is populated automatically via the view.
now let's work this out step by step..
1-Does your try throws an exception?? I mean do you catch anything in the catch block??
2- After you change the value to false, make a break point and watch the value of the last row to be changed.
Regards
|
|
|
|
|
Hi,
There is no exception thrown at all. It goes straight into the finally block from the last line of code in the try block.
I set a break point at the last line of code in the try block and watched the value of the 1st 10 rows of the checkboxcolumn. They were all set to false. But when it stepped into the next line of code (which is the "}" of the try block), they all turned back to null value. This means, it is at the end of the try block that they were switched back.
I just realised one thing. The datagridview is displayed when I press a search button. It is very strange that the false values are all switched back to null only the first time when the search button is pressed. They all remained set to false the second time onwards. Actually it has the same kind of problem with the row numbers display - it will never display the row numbers for the first time but it will from the 2nd time onward. Strange?!!
Thanks
-- modified at 21:12 Tuesday 29th August, 2006
|
|
|
|
|
Hello
printscreen12345 wrote: Strange?!!
Well, errors like these in Visual Studio are what keeps Borland on business;P
Anyway, My last question would be: Do you put the false value directly into the cells, or do you put some sort of a local reference field in the try block to hold it?? If you put it in a local field it will turn to null once the block is finished, otherwise really... I'm out of guesses.
printscreen12345 wrote: it is at the end of the try block that they were switched back.
I guess I'd pass out if I see something like that while debugging??
Regards
|
|
|
|
|
Hello,
I've tried various ways to solving my problem. First using the System.management I tried to get to the WMI data of Exchange but keep getting an Access Denied error.
What I did now is create a DLL in VB6.0 and set a COM reference to it in my C# project. When I use my code in the click event of a button, the code works fine (it creates a file with the size of the public folders). When I try to use it in a DLL, the code no longer works. Very frustrating. Been looking at this for days already.
The code stops when I call the function of the VB6.0 dll.
I've already tried changing the security in WMI but after restarting the WMI service, I still get the access denied error.
Very weird.
Can anyone help out ?
Jason
|
|
|
|
|
I'm certainly confused. What do you mean, "use it in a DLL". .NET assemblies are DLL's
only two letters away from being an asset
|
|
|
|
|
What I did is created the code in VB6.0 and saved it as a DLL.
From C# I added the DLL through the COM tab.
Then I used the function defined in the DLL. But the code only works when I use it in the click event of a button. If I want to save my code as a DLL, then it no longer works.
What I really want to do is access the WMI from Exchange. But with C# it's a pain in the ... . that's why I switched to this VB6.0 DLL import into C#. But even that seems a hard job.
You would suspect the code to work in the .net DLL if it works in a form.
Could this have to do with some sort of protection level of variables. I have the impression that the parameters passed to the function aren't getting through once the code is used inside a .net Dll.
|
|
|
|
|
I actually thought that this was the forum where you get answers quickly.
I found out that when using WMI, the permissions have to be set and the service had to run as administrator (although I was logged in as admin it still didn't work). Next to that the app.config file contained 2 \'s. In c# you have to use 2. But when it's a variable inside the app.config .net sort of translates it correctly. Giving 2 slashes caused the whole thing to crash.
So thanks for the help (though I found it all myself LOL)
|
|
|
|
|
killazzz wrote: I actually thought that this was the forum where you get answers quickly.
Considering CodeProject and every other forum out there is an all-volunteer effort, and we all have real lives and jobs that need our attention also, you can't really expect this 100% of the time, if at all...
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi anyone. (c#, or vb.net)
How I can get all list view items of another process? I think that I need to use windows api.
Once I got them, how i can list sub items of each item?
Ok, after that I need to get items text and sub items text.
Please, help me.
Thanks in advance.
|
|
|
|
|
System.Diagnostics.Process
|
|
|
|
|
Hi!
For that you'll definitely need to use the Win32 API.
Take a look at the LVM_* messages and the LVITEM struct in MSDN, for example LVM_GETITEMCOUNT and LVM_GETITEM .
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
As mav mentioned, you can do this using the Win32 API. However, be aware that this will only work for Win32-based applications; WinFX/.NET 3 apps that use new Windows Presentation Foundation (WPF) do not have HWNDs for individual controls, and neither do they have Win32 message pumps. Because of this, it will be impossible to get at the ListViewItems of another process (a WPF-based one) unless that process specifically chooses to expose it to you.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Dumbest. Movie. Title. Evaaar.
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Hi there, Can anyone help me with this problem?
I have two window forms Form1 and Form2. This Form1 i used the following to showing Form2.
Form1:
Form2 form2 = new Form2();
...
form2.Show();
Hide();
And then i want to make a link when it is clicked, it shows the Form1 and hide the Form2:
in Form2:
Form1 form1 = new Form1(); <-- this keep gives me error.
...
form1.Show();
Hide();
When i tired to click on the link on Form2 so that i can get back to Form1, it give me an error. The whole thing doesn't work... i remembered it used to be much easier to do it in VB6 but how does it work in C#...
If anyone knows please help me thanks!
|
|
|
|
|
Hello
Esay with the frustration.
now to sum up: You have to forms and you want to show them one at a time -ie. not both at the same time-.
1- Create a Form2 object in Form1
2- When you click the link
this.hide();
MyForm2.ShowDialog(); //This will block code execution until you close Form2
this.Show();
Regards
|
|
|
|
|
Thanks alot that really helps. I think i can use this for handle showing and hiding multi-forms one at a time.
|
|
|
|
|
to hide form 1 you need to use the "this" identifyer so that the form knows the correct form to hide, so this.Hide(); is the correct way to hide the form. Also unless you are planning on creating a new instance of form 1, you need to pass form1 over to form2 in the constructor similar to the following:
Form2.css
//Default Constructor
static void Form2()
{
InitializeComponents();
}
//Constructor to bring in Form1
static void Form2(Form frm1)
{
Form1 form1 = frm1;
InitializeComponents();
}
Then you can reference the already existing form 1 and show it by making the statement:
form1.Show();
this.Hide();
and the way you pass Form1 (in Form1.css) over to Form2 is:
Form2 form2 = new Form2(Form1);
At least I think what I have told you is correct.
|
|
|
|
|
Ok, thx for the advise! In fact i solved that prob a while ago when i read the first reply. It goes like this:
In Form 1:
public partial class Form1 : Form
{
private Form2 form2;
...
private void link1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
form2 = new Form2();
form2.Show();
Hide();
}
...
}
In Form 2:
public partial class Form2 : Form
{
private Form1 form1;
...
private void link1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
form1 = new Form1();
form1.Show();
Hide();
}
...
}
I think it works in showing and hiding between different forms if i only use the "new form()" within the link function but i'm not sure if this is a good practice though...
|
|
|
|