How to search through all items of a combobox in C#? [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a combobox, and I would like to search through every element in it.
How can I do this? (also the number of items is not the same everytime, but this is not so important).
I am using c# windows form application.

you can do this
for (int i = 0; i < myComboBox.Items.Count; i++)
{
string value = myComboBox.GetItemText(myComboBox.Items[i]);
}

Use a foreach loop. It will iterate all your items of ComboBox regardless of their count, e.g.
foreach(var item in myComboBox.Items)
{
// do something with your item
}

Related

How to read row one at a time in Datagrid Wpf c# [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
How can i read each row in Datagrid one at a time.
For example my datagrid has 5 data on it. And each data corresponds to a method / function in my C# solution.
I want to read it as data 1 then perform the corresponding function under that data.
then read data 2 then perform the corresponding function under that data 2. and so on..
Can anyone give me some idea how?
I assume you are not following MVVM, Get the Items From Your DataGrid like this,
var tmplist = (ObservableCollection<YourDataGridObject>)DataGrid.ItemsSource;
foreach (YourDataGridObjectitm in tmplist)
{
///Access elements
}

Need to convert SQL to Linq-To-SQL [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
select cast(' ' as varchar(1000)) as myfield, otherfield
from tab1;
I need to convert above SQL to Linq-To-Sql.
Maybe:
from item in dataContext.Items
select new { MyField = "", Item = item };
Unfortunately, AMAIK, there is no way to declare * in projection in LINQ. Thus to have all other fields alongside your MyField field, you should write them all.

How do I find the total of all the elements in an int array c# [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
As it says in the title, is there a code to find out the total of all the numbers in an int array element.
E.G
int [] Football = new int [5];
And say all the elements already had values, how would i find the total of them or reference the total of them so i could add it to a variable?
That is quite easy using LINQ:
Football.Sum();
You need to iterate over the elements. This is basic stuff and should be covered in any C# tutorial:
int total = 0;
foreach(int i in Football) {
total += i;
}
Or you can use LINQ:
int total = Football.Sum();

Update DataTable records by Id in C# [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Could anyone please suggest, I have a datatable with 100 records and want to update any 1 specific record based on id.
Here is an example, maybe it helps even if your reqirement is not that clear:
DataRow row = tableWith100Rows.AsEnumerable()
.FirstOrDefault(r => r.Field<int>("ID") == 4711);
if(row != null)
row.SetField("ColumnToUpdate", "new value");

Display member with biggest value member in ComboBox [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Any idea if in combobox exist feature that make display member with biggest value member?
Thank you in advance.
Since you didn't show any effort or code example, you can follow a structure like this;
int biggest = comboBox1.Items[0];
for (int i = 1; i < comboBox1.Items.Length; i++)
{
biggest = GetBigger(comboBox1.Items[i], biggest);
}
comboBox1.SelectedItem.Value = biggest;
static int GetBigger(int a, int b)
{
if (a < b)
return b;
return a;
}

Categories

Resources