Getting the column items in a datagrid
-
I have a datagrid that is having values from a database. I need the values in the second column (being zero index based, i know if there is any indexing i will index as 1) but i am totally unable to get these items. i don't want to query the database again because this will slow down my system so much. please assist on how i can get this items. I tried this but did not work:
ArrayList percentages = new ArrayList();
percentages.AddRange(dataGridInfo.Columns[1]);Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
-
I have a datagrid that is having values from a database. I need the values in the second column (being zero index based, i know if there is any indexing i will index as 1) but i am totally unable to get these items. i don't want to query the database again because this will slow down my system so much. please assist on how i can get this items. I tried this but did not work:
ArrayList percentages = new ArrayList();
percentages.AddRange(dataGridInfo.Columns[1]);Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
If you need [Edit] to process [/Edit] them(the datas) in memory I would go for a
List<YourClass> myList
and then set thedatagrid.DataSource = myList;
Somethin like://gets the data
public ... GetDatas(){
cmd.CommandText = "SELECT * FROM XYZ";//or "EXEC SomeProcedure" or....;
SQLDataReader dr = cmd.ExecuteReader();
MyClass curr = null;
List<MyClass> lst = new List<MyClass>;
while(dr.Read()){
curr = new MyClass();
curr.Myprop1 = dr.GetString(0);//or GetWhatever
...
lst.Add(curr);
}
...
return lst;
}//and outside, somewhere in your UI
var myList = GetDatas();
dataGridView1.DataSource = myListNow you have the List and you can LINQ or whatever;
modified on Sunday, February 28, 2010 11:35 AM
-
I have a datagrid that is having values from a database. I need the values in the second column (being zero index based, i know if there is any indexing i will index as 1) but i am totally unable to get these items. i don't want to query the database again because this will slow down my system so much. please assist on how i can get this items. I tried this but did not work:
ArrayList percentages = new ArrayList();
percentages.AddRange(dataGridInfo.Columns[1]);Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
Is this the asp.net gridview of the winforms datagridview, 2 very different beasites. Winforms you can use datagridview.columns[index] to get the column.
Never underestimate the power of human stupidity RAH
-
I have a datagrid that is having values from a database. I need the values in the second column (being zero index based, i know if there is any indexing i will index as 1) but i am totally unable to get these items. i don't want to query the database again because this will slow down my system so much. please assist on how i can get this items. I tried this but did not work:
ArrayList percentages = new ArrayList();
percentages.AddRange(dataGridInfo.Columns[1]);Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.