|
Use like a xml/config file where you store the ConnectionSring.
Without the pass if any.
And create a Utlity method that gets the connection from the config file.
|
|
|
|
|
|
Read some documentation(s)!!!
I would use the XLinq to read data.
OK
public static string GetConnection(){
try{
System.Xml.Linq.XDocument doc = System.Xml.Linq.XDocument.Load("confix.xml");
return doc.Element("Connection").Value;
}
catch{
return "failure";
}
}
<?xml version="1.0" encoding="utf-8" ?>
<Connection>"MyConnectionWithoutPassHere"</Connection>
|
|
|
|
|
Hi,
I have a Windows application, written in c# and in my application, I have a DataGridView that has 2 DataGridViewComboBoxColumns in it, along with a DataGridViewTextBoxColumn. The 2 ComboBoxColumns are each populated by a DataSet. For each row, the user selects an item from each of the ComboBoxColumns and enters a number into the TextBoxColumn. As an example, let's say the Color ComboBox has 3 choices in it: Red, Blue & Green and the Size ComboBox has 3 choices in it: Small, Medium & Large. In our example, for the first row, the user has selected Red from the Color ComboBox, Medium for the Size ComboBox and has entered "5" in the Qty TextBox. For Row 2, the user selected Green in that Color ComboBox, Large in the Size ComboBox and has entered "4" in the Qty TextBox.
Row...........Color(ComboBox).........Size(ComboBox)......Qty(TextBox)
----------------------------------------------------------------------------------
..1............Red...............................Medium......................5
..2............Green...........................Large.........................4
Once the user is done, this information is saved to a table. Let's also assume that this information was for January, 2010.
When the user starts a new month, (February, 2010, for example), their data could be exactly the same as January or it may change a little. If it IS the same or very close to the same, rather than force the user to reenter all of the information as they did in January, I'd like to be able to give them the option to "import" the data from January but still give them all the options that they had in January. What this means is that the Color ComboBoxColumn for each row still has Red, Blue & Green as its items that can be chosen, but for Row1, "Red" needs to be the selected item and for Row 2, "Green" needs to be the selected item. Keeping with that same idea, the Size ComboBox still has Small, Medium and Large as its items that can be selected for each row, but for Row 1, "Medium" needs to be set as the selected item and for Row 2, "Large" needs to be the selected item.
My DataGridView would be populated the exact same way as it did in January but the selected items that show would be the data that the user had chosen in January. Because I'm retrieving that data (what the user chose in Jan) from the database, I know that in the DataGridView cell for Row1, Color ComboBox, the selected item should be "Red". Since I know that, how do I set the selected item in that ComboBox to "Red"? If this was a straight ComboBox, I know how to set the SelectedItem (or SelectedIndex). But because this is a DataGridViewComboBox, it doesn't seem to work the same way.
Any ideas or suggestions will be greatly appreciated. If more information is needed in order to help me solve this, please let me know.
Thanks in advance.
Ron
|
|
|
|
|
Assume there are two classes: Zoo and Animals. Something like this:
public class Zoo{
public int Id;
public string Name;
public List< Animals > animals;
}
public class Animals{
public int Id;
public string Name;
}
Now, I have two generic lists:
1. List of Zoo
2. List of Animals
3. Any kind of collection (I cannot decide which one to use) which will have Zoo.Id and Animal.Id. This collection would be used as a map between Zoo and Animals. Here each Zoo will have multiple animals and same animal can be a part of multiple zoos.
I need to get the list of Animals in a Zoo and then set that value to Zoo.animals list. I am thinking to use LINQ. Something like:
foreach(Zoo zoo in zooList){
zoo.animals = (from animal in animalList
where collectionThree[animal.Id] = zoo.Id
select animal).ToList();
}
But since collectionThree cannot be a Dictionary/HashTable, this wont work. Any ideas how to do this?modified on Wednesday, March 10, 2010 10:56 PM
|
|
|
|
|
Union statement in SQL Server can be useful.
|
|
|
|
|
Or SortedList. Ex:
public SortedList<Animal, Zoo> map = new SortedList<Animal, Zoo>();
...
...
...
zoo.animals = (from animal in animalList
where map[animal].Id == zoo.Id
select animal).ToList();
}
or
public SortedList<int, int> map = new SortedList<int, int>();
...
...
...
zoo.animals = (from animal in animalList
where map[animal.Id] == zoo.Id
select animal).ToList(); modified on Wednesday, March 10, 2010 2:25 PM
|
|
|
|
|
Thanks!
SortedList is what I was looking for.
|
|
|
|
|
Your 3rd collection is necessary, in fact it breaks the object encapsulation IMO.
What you really need is a List<Zoo> property on Animal , and conversely a List<Animal> property on Zoo . All you need do is ensure that the lists are not accessible publicly, and methods are provided for addition / removal to both list properties "simultaneously" (i.e. adding an Animal to a zoo also adds that zoo to an animal). You will also need properties or methods for getting copies (so the originals are unalterable externally) of the lists.Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
Or make them totally unaware of each other as in:
class Animal{
public int Id{get;set;}
public string Name{get;set;}
}
class Zoo{
public int Id{get;set;}
public string Name{get;set;}
}
SortedList<int,int> animalZooJonction = new SortedList<int, int>();
var animalsInSpecifiedZoo = (from rec in animals
where animalZooJonction[rec.Id] == zoo
select rec).ToList();
While it is not as keen on respecting standars it is faster and it does consume less memory.
|
|
|
|
|
Thanks for the reply.
I have tried to make actual scenario simpler with that example. The actual code is a bit different. What you have said is there in the actual code as well except for having lists in both the classes.
|
|
|
|
|
I need to run an installer action under the current user context, while it is runned under System user's context.
How it is possible?
|
|
|
|
|
|
0) PDFWriter there only supplies an emulated printer in your printer list that will create your PDFs for you so doesn't have any programmatic interface for you to use.
1) You need to instead go for their SDK here: http://www.cutepdf.com/Solutions/FormSDK.asp[^]
2) If you hit snags with that, I suggest you use cutepdf's support options. CP is more about generic programming techniques, not software specific ones that belong to people unaffiliated with it.
|
|
|
|
|
Hi All!
I’ve made a class that inherits from ComboBox and have added MinDate, MaxDate, and Value properties. In the constructor of the class I set the default values I want for those properties (they can be overridden by setting the property).
I used the VS 2005 designer to place my custom ComboBoxes on my form, but the designer keeps assigning default values for MinDate, MaxDate, and Value which are overriding the defaults I set in the constructor. When I try and remove the designer code that just deals with the assignment of those three properties the designer adds them back in after the next edit.
Is there a way to still use the designer but not have it hijack my custom controls?
Thank you all in advance!
|
|
|
|
|
On your properties you need to have the DefaultValue attribute with your defaults in. This will then stop the designer automatically overriding your defaults. This will also give you Reset functionality in the designer.
E.g.
[System.ComponentModel.DefaultValue("My Default value")]
public string MyProperty{
set{
}
}
|
|
|
|
|
Thank you for the reply. This looks like what I’m looking for. However, the complier won’t let me set the DefaultValue to DateTime.Now (or any other DateTime object) and I’ve had no luck finding an answer on the net.
The complier complains with the error “An attribute argument must be a constant expression, typeof expression or array creation expression”
It seems like the Designer is setting all of these values because it wants to be able to display how my control would actually look when run, but I don’t care about that at design time, I’m just using the designer to line up my controls.
Is there a way to stop the designer from trying to “figure out” what my control would look like and just set its placement?
Thanks again!
|
|
|
|
|
Anticast wrote: However, the complier won’t let me set the DefaultValue to DateTime.Now (or any other DateTime object) and I’ve had no luck finding an answer on the net.
In orther to use it as default value, use this: [DefaultValue(typeof(DateTime), "Now")]
NOTE: When using atribute DefaultValue, you must also set the default value to the code. this attribute only tells to your IDE. And IDE (VS08 or others) removes property from auto generated code. DateTime changes and it is impossible to use it as default value without Type converzion. Introduction to the TypeConverter
Anticast wrote: Is there a way to stop the designer from trying to “figure out” what my control would look like and just set its placement?
I do not understand you with this. Are you looking into this.DesignMode property in order to change behaviour?. Designer can't try to figure out your controls look. Every time you compile IDE uses its compiled info and then it displays on designer by using latest build
|
|
|
|
|
If you don't want the designer to serialize your properties, add a System.ComponentModel.DesignerSerializationVisibilityAttribute set to NeverDave
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Awesome! This did exactly what I was looking for. Thank you!
For anyone else that is using ComboBoxes (or similar controls, I'm sure) I also had to add:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
new public ComboBox.ObjectCollection Items
{
get
{
return base.Items;
}
}
to get the Designer to stop adding items to my collection. Without this the constructor was adding its items, then the designer added those items again.
Thanks again!
|
|
|
|
|
HI All,
I need to implement chroma key features.
I need to draw a graphics on a pictures box and apply to this a chroma key at background color (es Violet) to see a playback video that is under this control.
I must see a graphics and a playback video at the same time.
Can you help me with example?
Thanks.Alex
|
|
|
|
|
Hi,
Is there any way to find out if a SqlConnection has an open SqlTransaction?
Basically I have an object with a method that accepts a SqlConnection as a parameter. This method is called from a number of different application. Sometimes the SqlConnection has a SqlTransaction and other times it doesn't.
So what I need to be able to do is something along the lines of
public bool Post(SqlConnection cn, int ID)
{
SqlTransaction trans;
if(cn.HasTransaction)
{
trans = cn.Transaction;
}
else
{
trans = cn.BeginTransaction();
}
return true;
}
Is there anyway to get something similar?
Thanks,
David
|
|
|
|
|
I rather suspect that you could just check to see if the Transaction is null or not on the command."WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
There is no command being passed in, just a connection.
So when I create a command object I want to do something like.
SqlTransaction trans = null;
cmd.Connection = cn;
if(cn.HasTransaction)
{
trans = cn.Transaction;
}
else
{
trans = cn.BeginTransaction();
}
cmd.Transaction = trans;
|
|
|
|
|
Shouldn't you track that yourself?
|
|
|
|