|
i am creating a list like this
vd.Department = (from dept in vd.Employees
select new Department
{
DepartmentID = dept.DivisionID,
DepartmentShortName = dept.Division
}).Distinct();
DepartmentShortName will have multiple values [Accounts, Production, Technical etc..]
What i want to do is to change the values so if it is Accounts =1, Production = 2.
How can i change this without doing foreach loop?
|
|
|
|
|
Set up a map:
Map<string, int> divisions = { "Accounts" => 1, "Production" => 2, ... etc };
(you can do this once, probably in a static initialiser)
and then use it in the query:
vd.Department = (from dept in vd.Employees
select new Department
{
DepartmentID = dept.DivisionID,
DepartmentShortName = dept.Division,
DivisionIndex = divisons[dept.Division]
}).Distinct();
|
|
|
|
|
Bob, please excuse my ignorance here, but is this Map code SQL ? Or am I hallucinating C# has a type of object similar to Dictionary I've never heard of before ? At first I thought "VB," but, then, the presence of semi-colons in both OP's, and your code, ruled that out.
Please enlighten.
thanks, Bill
"Every two days we create as much information as we did from the dawn of civilization up until 2003". Eric Schmidt of Google.
|
|
|
|
|
Hi all,
first thing , Sorry for posting my question again as another thread.
ResultFilterExpression = this.DataGridViewColumn.DataPropertyName + "not IN (" + FilterValue + @")";.
The above filter is working fine but only the problem , I have to give the filter parameter as NOT IN('CATAGORYA,'CATAGORYB') instead of NOT IN (CATAGORYA, CATAGORYB)
How I can modify the above filter condition for that
Pls help
Pol
|
|
|
|
|
if i understand the question you want to convert "CATAGORYA, CATAGORYB" to "'CATAGORYA,'CATAGORYB'" (i.e. wrap the individual values in single quotes)
try
string[] values = FilterValue.Split(',');
StringBuilder bldr = new StringBuilder();
bool isFirst = true;
foreach (string s in values)
{
if (!isFirst)
{
bldr.Append(",");
}
bldr.Append(string.Format("'{0}'", s));
isFirst = false;
}
FilterValue = bldr.ToString();
Pedis ex oris
Quidquid latine dictum sit, altum sonatur
|
|
|
|
|
|
Anybody can help me to sort out this problem
When I give multiple value , it doesnot filter for example
case "in":
ResultFilterExpression = this.DataGridViewColumn.DataPropertyName + " IN ('" + FilterValue + @"')";
break;
It works only one parameter . After comma it will not work
For example the catagory column, When I give
in('CatagoryA') - it will work but
in('CatagoryA, CatagoryB) - it doesnot work
Pls you or anybody can give a solution it would be appreciate.
With Thanks
Pol
|
|
|
|
|
You've already asked the question. Repeating questions does not guarantee a quicker response. See my response to your other post.
|
|
|
|
|
|
Hi
I want to add 'IN' and 'NOT IN' condition along with following program to filter datagridview
case "LIKE": ResultFilterExpression = this.DataGridViewColumn.DataPropertyName + " LIKE '%" + FilterValue + "%'"; ResultFilterCaption += "\n = '.." + FilterValue + "..'"; break;I want to add the condition 'IN' and 'NOT IN' filter cindition with datagridview Please help
FilterValue = 'A','B'
case filter = "IN"
ResultFilterExpression = this.DataGridViewColumn.DataPropertyName + " IN + FilterValue + ";
case filter = "NOT IN"
ResultFilterExpression = this.DataGridViewColumn.DataPropertyName + "not IN + FilterValue + ";
Please how I can impliment the filter 'IN' condition with datagridview.
With Thanks
|
|
|
|
|
Try ResultFilterExpression = this.DataGridViewColumn.DataPropertyName + "not IN (" + FilterValue + @")"; .
Here filtervalue is should be a list of comma separated values e.g 1,2,3,4.
|
|
|
|
|
Thats not working I given your code as follows. It should be string
case "in":
ResultFilterExpression = this.DataGridViewColumn.DataPropertyName + " IN ('" + FilterValue + @"')";
break;
It works only one parameter . After comma it will not work
For example the catagory column, When I give
in('CatagoryA') - it will work but
in('CatagoryA, CatagoryB) - it doesnot work
Pls you or anybody can give a solution it would be appreciate.
With Thanks
Pol
|
|
|
|
|
Member 3708190 wrote: in('CatagoryA, CatagoryB)
should be
Member 3708190 wrote: in('CatagoryA', 'CatagoryB')
|
|
|
|
|
I tried by both
"CatagoryA"
'CatagoryA'
but not working
|
|
|
|
|
Very Sorry It is working fine, Many Many Thanks.
Please
How the condition in code can be modified by way to avoid the giving string notation " " in filter .
Just we need to give like CatagoryA, CatagoryB. not 'CatagoryA','CatagoryB'
Many Many Thanks
Pol
|
|
|
|
|
Strings must always be enclosed within delimiters (either ' or "). How else can the expression parser know the beginning and end of the string?
|
|
|
|
|
after comma will start another catagory. There is no any comma inside the name of a catagory.
So after the comma will start another catagory. Only thing I have to put the " mark before and after of each comma.
I am beginner in C# . So I am seeking a help
With many thanks
Pol
|
|
|
|
|
You cannot do that. That is how strings work in programming, they need a delimiter.
|
|
|
|
|
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!!
|
|
|
|