473,322 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

access table cell by name not by index?

I have a dynamic datagrid in which the number of columns of not fixed, the
number of columns is selected from a dropdown.

I have one column header called "Brand/Model" and on the onItemDataBound i
want to modify the values relates to this column.. the problem is because the
index value is not fixed i can't use .. e.Item.Cells[int].Text

My question is how can i reference the cell by the cloumn header "BrandModel"?
is there a another way this solve this?

many thanks in advance..
Jul 21 '05 #1
7 1805
Huzz,

Never access a datagrid using the grid itself, access it by using the
datasource of it.

I hope this helps?

Cor
Jul 21 '05 #2
Cor thanks for your reply..
I don't know how to access it by datasource.. can you show me what code i
need to write.. or any good article?

many thanks
"Cor Ligthert" wrote:
Huzz,

Never access a datagrid using the grid itself, access it by using the
datasource of it.

I hope this helps?

Cor

Jul 21 '05 #3
Huzz,

I made this sample the day before yesterday however the OP did not give any
reaction on this.
However maybe it is now helpfull for you.

The only thing you have to do for it is drag a datagrid and a button on a
form paste this code bellow in, set the events in the code and run.

private void button1_Click(object sender, System.EventArgs e)
{
DataView dv = (DataView)this.dataGrid1.DataSource;
DataTable dt = dv.Table;
DataRow dr = dt.NewRow();
dr.ItemArray = new object[] {2,"002","Thee - Ceylon"};
dt.Rows.Add(dr);
int i = 0;

if ((string)dv.Sort == "[ItemId]") {i = dv.Find("002");}
else if (dv.Sort == "[Quantity]") {i = dv.Find(2);}
else if (dv.Sort == "[ItemName]") {i = dv.Find("Thee - Ceylon");}
this.dataGrid1.Select(i);
}
private void FormLoad(object sender, System.EventArgs e)

{
DataTable dt = new DataTable();
dt.Columns.Add("Quantity");
dt.Columns.Add("ItemID");
dt.Columns.Add("ItemName");

for (int i = 0; i < 3; i++) {
DataRow dr = dt.NewRow();
dt.Rows.Add(dr);}

dt.Rows[0].ItemArray = new object[] {3,"001","Coffee - Black"};
dt.Rows[1].ItemArray = new object[] {1,"015", "Donut - Boston Creme"};
dt.Rows[2].ItemArray = new object[] {1,"005","Donut - Plain"};
DataView dv = new DataView(dt);
this.dataGrid1.DataSource = dv;
}

}

I hope this helps?

Cor
Jul 21 '05 #4
Since you know the name of the column you could iterate through the
column names and grab the index of the desired column. Here's an
example that just spits out the column names and their index.:
private void dg1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = (ListItemType)e.Item.ItemType;
if(itemType == ListItemType.Header)
{
for(int i = 0; i < dg1.Columns.Count; i++)
{
Response.Write("Column Text = " + dg1.Columns[i].HeaderText.ToString()
+ " - Index = " + i.ToString() + "<br>");
}
}
}

Jul 21 '05 #5
Vince,

Yes and then? What do you want to tell me?

Cor
Jul 21 '05 #6
Sorry. I guess that I click the wrong "Reply" link. I just meant to
offer huzz another alternative.

Jul 21 '05 #7
Thanks everyone for your help.. i'll have a go at it tomorrow sometime..

"huzz" wrote:
I have a dynamic datagrid in which the number of columns of not fixed, the
number of columns is selected from a dropdown.

I have one column header called "Brand/Model" and on the onItemDataBound i
want to modify the values relates to this column.. the problem is because the
index value is not fixed i can't use .. e.Item.Cells[int].Text

My question is how can i reference the cell by the cloumn header "BrandModel"?
is there a another way this solve this?

many thanks in advance..

Jul 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: yurps | last post by:
Hello here is my html, if you click the missing image in the first column on the left, the div is shown, when clicked again the div disappears...but the bottom border disappears as well...Is there...
14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
41
by: Ruby Tuesday | last post by:
Hi, I was wondering if expert can give me some lite to convert my word table into access database. Note: within each cell of my word table(s), some has multi-line data in it. In addition, there...
1
by: Abareblue | last post by:
I have no clue on how to insert a record into access. here is the whole thing using System; using System.Drawing; using System.Collections; using System.ComponentModel;
28
by: Giggle Girl | last post by:
Can someone show me how to insert a row at any given row index of an already created table? It only has to work in IE6 (used on intranet at work). Specifically, if a table is 20 rows in total...
4
by: alexandre.brisebois | last post by:
Hi, I am using access 2003, I would like to know if there is an option to reorganize the tables in a maner that is readable, as we can do in sql sever 2000 or 2005. I have been given a database...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
5
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
2
by: TG | last post by:
Hi! I am trying to export only the visible columns from a datagridview in my windows form in VB 2008. Should't it be no comma after the first row where the headers are? Also should...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.