Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I want to concatenate two combo boxes value into 1 column of GridView in C#. I am using this code but it not concatenate it..
private void linetotal_KeyUp(object sender, KeyEventArgs e)
{
if(e.KeyCode==Keys.Enter)
{
object[] values = { cbxclassstd.Text,cbxfee.Text,
feeamount.Text,disc.Text,linetotal.Text};
this.dgvvoucher.Rows.Add(values);
}
}
Use string.Join to concatenate your Combobox's values into one column:
this.dgvvoucher.Rows.Add(string.Join("", values));//Or string.Join(",", values)
And if you just need to concatenate first two items:
this.dgvvoucher.Rows.Add(string.Join("", new[] { values[0] , values[1] }));
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a string array as follows:
string[] stringArray = { "1122|false", "1123|true", "1124|true", "1125|false" };
In essence, it is broken down by id|active where for example id is say 1122 and active is true or false.
Say my id was 1123, how would I search this array to get the value of true in this case? I understand Substring needs to be used with IndexOf but not sure how to tie it together.
Little bit of LINQ and String.Split should do the trick.
string[] stringArray = { "1122|false", "1123|true", "1124|true", "1125|false" };
int id = 1123;
var itemWithGivenId = stringArray
.SingleOrDefault(s => int.Parse(s.Split('|')[0]) == id);
Console.WriteLine(bool.Parse(itemWithGivenId.Split('|')[1]));
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Is it possible to look up if a string in contained in an Array, with a switch case?
string text = "blalbac";
string arr[] = {"a","b","c"};
switch (text)
{
case arr.Contains(filename):
//do..
break;
}
I’m not sure what you’re trying to do. Do you want something like
foreach(string item in arr)
{
if(text.Contains(item))
{
...
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I define the arraylist on my form2, sending it using the constructor to form 3, where it is filled. However, I want the internal array's size to be user defined.
How would i go about doing this?
Looks like this for now, but it doesn't work.
private void bCapturar2_Click(object sender, EventArgs e)
{
int k=0;
k=int.Parse(textBox1.Text);
((paciente)Datos[i]).num_asist = k;
lAsistentes.Visible = true;
tbNom_Asist.Visible = true;
((paciente)Datos[i]).asistentes = new string[((paciente)Datos[i]).num_asist];
bCapturar2.Visible = false;
}
You can set the capacity for your ArrayList on declaration
var tenItemArrayList = new ArrayList(10);
If asistentes is an ArrayList, you still can change the value for capacity that way...
((paciente)Datos[i]).asistentes.Capacity = ((paciente)Datos[i]).num_asist;
However the new capacity cannot be less than the current. Otherwise you'll get an exception.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I wanted to try some examples in C# using collections and generics but I am stuck at this example.
This is my code in c#,
public List<string> CurrentCount(int week, int year)
{
List<string> lst = new List<string>();
lst.Add("current:");
lst.Add("10");
lst.Add("target:");
lst.Add("15");
return lst;
}
It gives me result like this :
["current:","10","target:","15"]
But I want it like this :
["current": 10,"target": 15] or
["current": "10","target": "15"]
Any ideas will be helpful.
Thanks.
You want a Dictionary, not a List.
var dict = new Dictionary<string, int>();
dict.Add("current", 10);
dict.Add("target", 15);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
How apply linq select to string array in C#
ex :
string[] result;
...
result.Select(..)
?
Thanks.
You pass in a lambda function that tells the system what you want to do with each string.
string[] result;
...
var newList = result.Select(s => {do something with s});
The function can do most anything that takes a string as an input and returns a value - it doesn't even have to return a string! For example, if the strings contained numeric characters, you could return a collection of numbers:
IEnumerable<int> newList = result.Select(s => int.Parse(s));
Note that the original array will not be changed.