|
Try with "" on the CategoryA .
|
|
|
|
|
No, it is not working . I tried with "CatagoryA" on filter condition. But it si not working
Pol
|
|
|
|
|
Can you help how to give the condition like
CatagoryA, CatagoryB
not 'CatagoryA','CatagoryB'
Many Many Thanks
|
|
|
|
|
Do you need to use control characters in the string?
"\'CategoryA\'"
|
|
|
|
|
Options to check logical equivalence of Boolean expressions
|
|
|
|
|
The standard way is to do an if condition clause.
You can use the ternary operator[^].
Apart from these & | ^ ! ~ && || true false is the full set of bool operators that you can use for comparisions / logical calculations.
This[^] is where all operators are listed.
|
|
|
|
|
Lets say I have a form where someone can catalog a multiple people's Name and their State and City?
Assume I already have all the State/Cities in database. (a table for each state, with cities listed in each table)
The Name field will be a TextBox. And the State & City fields will be ComboBox (DropDownLists).
One row (for the entry of one person) already exists in the form. But I want the user to be able to dynamically add rows of entries by pressing an "Add Person" button.
The next step is where I'm struggling. In each dynamically added row of fields, I would like the second ComboBox (Cities) to be populated depending on which State is chosen in the first Combo Box. Also, the Cities ComboBox will remain disabled until the State ComboBox is chosen.
My code looks something like this:
public ComboBox cbState;
public ComboBox cbCities;
public static int NumberOfPeople = 1;
private void btnAddNewPerson_Click(object sender, EventArgs e)
{
NumberOfPeople++;
TextBox txtPerson = new TextBox();
txtPerson.Name = "Person" + NumberOfPeople;
Panel.Controls.Add(txtPerson);
cbState = new ComboBox();
cbState.Name = "State" + NumberOfPeople;
cbState.Enabled = true;
cbState.DropDownStyle = ComboBoxStyle.DropDownList;
Panel.Controls.Add(cbState);
cbCity = new ComboBox();
cbCity.Name = "City" + NumberOfPeople;
cbCity.DropDownStyle = ComboBoxStyle.DropDownList;
cbCity.Enabled = false;
cbCity.SelectedValueChanged += new System.EventHandler(this.ChangeState);
Panel.Controls.Add(cbCity);
}
private void ChangeState(object sender, EventArgs e)
{
..... Don't know how to properly identify the dynamically created City ComboBox that is in the same row as the State ComboBox that was just changed, and manipulate/populate it.....
}
Anyone able to help me solve this issue??
I'd greatly appreciate it!!
|
|
|
|
|
You might be able to do that sort of thing with a DataGridView.
But, personally, I find it to be a rather poor design. I would prefer that the "Add Person" button brought up a dialog. One benefit of this is that the user can cancel the entry without affecting the form (I assume that the way you described would require removing the added controls).
How you display the list of "people's Name and their State and City" would likely need to change as well -- I would probably use a TreeView rather than a bunch of TextBoxes and ComboBoxes.
|
|
|
|
|
How I'd do this is:
- Maintain a list of data objects, containing the data you want:
class Person : BaseNotifier {
private string name;
public string Name { get { return name; } set { name = value; Notify('Name'); } }
private string state;
public string State { get { return state; } set { state = value; Notify('State'); } }
}
(BaseNotifier is a simple implementation of INotifyPropertyChanged, see end of post), and in your main class:
List<Person> people = new List<Person>();
- Create a custom control that can be bound to a person:
class PersonPanel : Panel, INotifyPropertyChanged {
TextBox nameTextBox;
ComboBox stateCombo;
public static readonly string[] States = { "NSW", "SA", "WA", "NT", "ACT", "TAS" };
public PersonPanel(){
Width = 200;
Height = 30;
Controls.Add(nameTextBox = new TextBox());
nameTextBox.Left = nameTextBox.Top = 5;
nameTextBox.TextChanged += (s, e) => Notify("Name");
stateCombo.SelectedIndexChanged += (s, e) => Notify("State");
}
public string Name {
get { return nameTextBox.Text; }
set { nameTextBox.Text = value; }
}
public string State {
get { return (string)stateCombo.SelectedItem; }
set { stateCombo.SelectedItem = value; }
}
public event PropertyChangedEventHandler PropertyChanged;
private void Notify(string property){
PropertyChangedEventHandler h = PropertyChanged;
if(null != h) h(this, new PropertyChangedEventArgs(property));
}
}
The notification is so two way data binding can work.
- When you add a new person, create and bind one of these to a new Person object
void AddNewPerson(){
Person person = new Person();
if(people.Count > 0) person.State = people[people.Count - 1].State;
people.Add(person);
PersonPanel panel = new PersonPanel();
panel.DataBindings.Add("Name", person, "Name");
panel.DataBindings.Add("State", person, "State");
Panel.Controls.Add(panel);
}
This gives you a nice separation of the data part and the UI, allowing you to change view driver or easily store the data in a database or file system.
BaseNotifier is a simple implementation of INotifyPropertyChanged to avoid typing the same thing several times:
public abstract class BaseNotifier : INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
protected void Notify(string property){
PropertyChangedEventHandler h = PropertyChanged;
if(null != h) h(this, new PropertyChangedEventArgs(property));
}
}
|
|
|
|
|
If you are going with this approach and the dynamic controls are the same for each new 'row' then it would be easiest to create a new control that contains the dynamic controls and their logic (essentially 'Panel' in your above code but as a distinct control)
That way you can have your new control fire events, when a new control is added you can have the other controls hook up to its events and react accordingly
Pedis ex oris
Quidquid latine dictum sit, altum sonatur
|
|
|
|
|
You already have three excellent answers from PieBaldConsult, BobJanova, and GParkings that each give you valuable insights, and strategies.
While I'm not sure why PieBaldConsult why considers a DataGridView a "poor design" in this particular scenario: and, I have to confess my bias: I just hate the DataGridView, and think it's an ugly thing, so in that sense I certainly agree you should not use it. I also like PBC's idea of using a dialog (or pop-up Form) which gives the user the option to Cancel, before automatically adding another "virtual row of Controls" to your Panel.
If you automatically add a new 'Person object, and the user decides they really didn't want to do that: what do you do now: can the user delete a selected 'Person object: if so, how ?
But, the larger question I have about your design here is what appears to be the absence of your using a database to write and store, at some point, the collection of 'Person objects. You already use database tables for State/City correlations. Can we assume that, at some point, you are going to enumerate the list of 'Person objects and write them to a database ?
And, I'd like to respond to your question exactly as asked: your code shows you are creating three new controls, with each addition of a new user, and adding them to the Panel.
A better strategy, imho, is to create a UserControl that has all three controls, and add a new one of those with each click of the 'Add Person' button to the Panel: by using docking properly, and setting z-order, they'll form an ordered list, naturally, and you can set scrollbars in the Panel to visible for easy access to the whole list, should it overflow the Panel bounds.
Note that using UserControls would handle the problem of deleting entries easily: since you can maintain a "currently selected 'Person instance" variable that contains a reference to the UserControl that currently has "Focus."
Within the UserControl, you can have a public property for each of the three Controls, whose value is set to the instance of the Control, in the UserControl 'Load event, and thus are easily accessible from your Panel, or its containing Form. Or, for more limited exposure (parsimony): have the three public properties be only the text value of the UserName control, and the ComboBox Index properties of the State and City objects.
imho, Events come into play here when someone changes their choices for values in the three "field entry" facilities. And, imho, Bob Janova, covers that exhaustively in his answer. I've had such a negative experience using PropertyNotification in WinForms, that I'd handle this by invoking static methods in a static class to update, but perhaps my thorough study of Bob's example ... which is going to happen ... will straighten my head out about PropertyNotification, and I'll have a "conversion experience"
The question of how the newly created 'Person object "inherits" the last State name used is easily solved by having a variable of Type int (or you could be using an Enum) called 'LastStateSpecified, or whatever: set it every time the act of adding a new 'Person object is completed, and the State field is set. Then, when you create the next 'Person object: use the value of that variable ...as the Combobox Index ... to set the new ComboBox to the correct State.
best, Bill
"Every two days we create as much information as we did from the dawn of civilization up until 2003". Eric Schmidt of Google.
modified 25-Feb-12 2:40am.
|
|
|
|
|
If we have 2 form (Form1 & Form2) whitin a project
and we added an object (for example textBox1) to
Form1, how can we access to textBox1 from Form2.
i have done this in form2 by these codes
{
Form1 fr = new Form1();
.
.
.
}
but fr doesn't show textBox1 durring writing codes.
i suppose fr.textBox1 must be correct but it is not.
please tell ne how can i do that.
|
|
|
|
|
The simplest but wrongest way would be to make the TextBox public.
A better way is to make a public property that allows the other form to get and/or set the Text property of the TextBox.
There are other ways that may be more appropriate to your situation, but we would need to know more about what you are trying to do.
However you do it, you may have to protect against cross-thread access problems.
|
|
|
|
|
I want to get the properties value of that object and change it to
a new value as I want.
|
|
|
|
|
You would have to change the access modifier for the textbox.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
by changing the modifier I only can get the properties of
that object (the values can be read) how can we set the
properties to a new value?
|
|
|
|
|
Pass value between forms using events[^] explains the correct way to do such things.
What you had, creating yet another Form1, is not going to work, as you are looking at one instance of Form1 and programmatically changing another unrelated instance.
Making Controls public would work but is hardly acceptable, as now "the whole world" could modify, move, resize, etc. said Control.
|
|
|
|
|
|
I hope this will help:
Form1 frm=new Form1();
frm.Show();
TextBox textBox=frm.Controls.Find("textBox1",false)[0] as TextBox;
textBox.Text = "new text";
|
|
|
|
|
I'm working on a custom Attribute. What I'd like is to have it take a parameter (e.g. [MyAttribute(foo)] ), but the type I want to use isn't allowed (non-constant).
So, I made my Attribute abstract and derived other Attributes to specify the desired values:
class FooAttribute : MyAttribute
{
public FooAttribute() : base ( foo ) {}
}
class BarAttribute : MyAttribute
{
public BarAttribute() : base ( bar ) {}
}
This works as expected except that instances of both derived Attributes can then be applied and they don't get flagged as duplicates (of MyAttribute); from a certain point of view, AllowMultiple=false should disallow multiple instances of the base class. In practice this doesn't happen, and that's understandable, but I want to find a way to get it to work that way.
I investigated the TypeId property thinking that would work, but it doesn't seem to.
Has anyone here happened upon this situation and found a solution?
Currently my code is just using the first instance of MyAttribute it finds, but I'm considering having the code throw an Exception if it finds multiples -- does anyone here have an opinion on which course of action is better?
|
|
|
|
|
I am making a program in which I established connection with sql server using DSN. I am using ODBCConnection class. I want to check that, DSN which is created is for access or sql server. I did google but not getting helpful information. I am using c# and visual studio 2008.
Thanks.
|
|
|
|
|
Unless you are developing your program to work with both -- as in using Access for testing, but SQL Server for production, then I don't really see a need to do this.
If you are doing that, then I might suggest that you create a table with that information and query it.
If, on the other hand, you are given a Connection and want to determine which it is, then the best I can say is to use the GetSchema method and examine the resultant table for clues.
|
|
|
|
|
I need to validate dsn name that it is valid or not. Like we can choose any dsn name which is for access, excel, or sql server.
|
|
|
|
|
If you want to check whether or not a given DSN points to your database, then I suggest making a Connection, calling GetSchema, and looking for your tables.
|
|
|
|
|
Hi All,
I have a printed document with lots of check-boxes, I must automatically detect which check-boxes are marked, and save these into a database. (Using C#)
Can anybody give me some hints where to start digging or examples of how I should start on this task.
Thanks alot.
|
|
|
|
|