473,386 Members | 1,609 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,386 software developers and data experts.

DataGrid filled from runtime created DataTable is non-editable!

I want to be able to display the tuples of a select query (which may change
at runtime, so no prior knowledge for column characteristics) and edit them
as well.

I used this code, that executes the select, gets schema from the datareader,
creates a table that can host data of that type, fills it with data from the
datareader and then binds it to a DataGrid.

The problem is that although i seem to do everything correctly and although
all the readonly flags are set to false, the DataGrid cannot be edited!!

Any ideas?

Here's the code:

DataRow myRow;
DataTable tbContInfo;
DataTable tbCont = new DataTable("CONTACTS");
Connection conn = new Connection();
conn.Open();
SqlCommand SQLCommand = new SqlCommand();
SQLCommand.CommandText = textBox1.Text;
SQLCommand.Connection = conn.getConn();
SqlDataReader data = SQLCommand.ExecuteReader(CommandBehavior.KeyInfo);
data.Read();
//Get schema of query results and construct the appropriate DataTable.
tbContInfo = data.GetSchemaTable();
for (int j=0;j<tbContInfo.Rows.Count;j++)
{
DataColumn myColumn = new DataColumn();
myColumn.DataType = tbContInfo.Rows[j]["DataType"].GetType();
myColumn.ColumnName = tbContInfo.Rows[j]["ColumnName"].ToString();
myColumn.ReadOnly = false;
tbCont.Columns.Add(myColumn);
}
tbCont.BeginLoadData();
//Load newly constructed DataTable with data from reader.
if (data.HasRows)
while (data.Read())
{
myRow = tbCont.NewRow();
for (int i=0;i<data.FieldCount;i++)
{
if (!data.IsDBNull(i))
myRow[i] = data.GetValue(i);
}
tbCont.Rows.Add(myRow);
}
tbCont.EndLoadData();
data.Close();
conn.Close();
dataGrid1.ReadOnly = false;
dataGrid1.SetDataBinding(tbCont,"");
Nov 16 '05 #1
0 1823

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

Similar topics

0
by: chrisben | last post by:
Hi, I made a DataTable table and add four DataColumn to it. Then I created a DataView by calling dbv=new DataView (table). Then I insert some rows to the dataview and bind it to my datagrid as...
2
by: Ben | last post by:
Hi, I'd like to have a datagrid that has a dropdownlist in the pager control for setting the page size. I can get the control into the pager inside the datagrid itemcreated event by checking for...
11
by: rkbnair | last post by:
I have created a datagrid in my aspx with the 'AllowSorting' property to true. When clicking on the column header, the page refreshes. However the sorting is not done. Am I missing anything? I...
5
by: Gary Blakely | last post by:
I'm giving this post another try - it can't be too difficult for everyone.... In the program below, the web page has dataGrid1. the only thing that has been done to it at design time is to...
6
by: Eric Broers | last post by:
LS, Assume I have a datagrid, which is filled by an SQL statement (Select * from Customer). The Customers table contains 4 columns and 10 rows. Now, I want to fill 10 strings with the datagrid...
11
by: Fred Nelson | last post by:
I have an application in which it would be VERY beneficial if I could obtain the names of the colums in a datagrid. For example dim datagrid1 as new datagrid datagrid1.datasource = (stored...
0
by: Bob Davies | last post by:
Hi I have a webservice that retrieves data from a database, this is then returned to the calling client application built in windows forms within a dataset, however upon attempting to create...
4
by: youngster94 | last post by:
Hi all, I'm having a little trouble with some code Im writing and Im thinking there has to be an easy fix. What Ive done is fill a dataset via 3 odbcdataadapters. The dataset is also the...
0
by: Matt | last post by:
I derived my own custom class from the datagrid class. I overrode the ProcessCmdKey Function, like this, to catch the up and down arrow keys: ====== Protected Overrides Function...
4
by: gh | last post by:
I create the columns for the asp.net datagrid at runtime and populates them. I have a template column for checkboxs I created at runtime as well. The user selects the product they want by...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.