473,499 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGridView, DataSource, Columns and Datatable.

Hi,

I have been trying to see if I can do the following:

1. Create a DataGridView
2. Create 2 columns in the DataGridView (1 textbox and the other combobox)
3. Create a DataTable containing my data. (AutoGenerateColumns is true).
The data is 2 columns of System.String cell.

4. If I assign the DataTable to DataGridView.DataSource, I get 4 columns. 2
column
from (2) and 2 columns from (3).

I am not certain is there a way to use DataTable in (3) to populate the 2
columns I created in (2). E.g. through proper column naming or other technic.

Any help is appreciated.

--
George
May 5 '06 #1
8 34206
Hi George,

Maybe I do not understand your question but....maybe you could first assign
the DataTable to your Grid and then modify the autogenerated columns to
achieve what you need.

Regards,

Hector Obregon
http://msdnfan.blogspot.com
"George" <wa**@nospam.nospam> wrote in message
news:F9**********************************@microsof t.com...
Hi,

I have been trying to see if I can do the following:

1. Create a DataGridView
2. Create 2 columns in the DataGridView (1 textbox and the other combobox)
3. Create a DataTable containing my data. (AutoGenerateColumns is true).
The data is 2 columns of System.String cell.

4. If I assign the DataTable to DataGridView.DataSource, I get 4 columns.
2
column
from (2) and 2 columns from (3).

I am not certain is there a way to use DataTable in (3) to populate the 2
columns I created in (2). E.g. through proper column naming or other
technic.

Any help is appreciated.

--
George

May 5 '06 #2
Hi George,

Thanks for your post!

To get what you want, we should set AutoGenerateColumns property to false.
This tells the DataGridView do not generate extra default columns for the
datasource, and you take care of the column generating.

Then we should set the 2 added columns' DataProperyName property to
corresponding DataColumn.ColumnName.

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 8 '06 #3
Hi Jefferey,

Thanks. I got it to work. However....

I notice that the DataGridView is "readonly". I am not able to modify
contents, even if I set the DataGridView ReadOnly to false.

Is this the normal by-product of DataSource binding?

Or is there a way to make DataGridView cells modifiable? Even better, can
these modification update Bound-DataSource, e.g. a DataTable? That will be
cool.

Thanks for any help.


--
George
""Jeffrey Tan[MSFT]"" wrote:
Hi George,

Thanks for your post!

To get what you want, we should set AutoGenerateColumns property to false.
This tells the DataGridView do not generate extra default columns for the
datasource, and you take care of the column generating.

Then we should set the 2 added columns' DataProperyName property to
corresponding DataColumn.ColumnName.

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 19 '06 #4
Hi Fabian,

Thanks for your feedback!

By default, users can edit the contents of the current DataGridView text
box cell by typing in it or pressing F2. This puts the cell in edit mode if
all of the following conditions are met:

1. The underlying data source supports editing.
2. The DataGridView control is enabled.
3. The EditMode property value is not EditProgrammatically.
4. The ReadOnly properties of the cell, row, column, and control are all
set to false.

So your symptom is not the default behavior. You may check all the above 4
conditions to get the default editing behavior.

Hope it helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 22 '06 #5
Hi Jeffrey,

I verified point (2) to (4) of your comments. I have all the settings
correct.

Regarding comment (1), I have further questions on it.

**
1. The underlying data source supports editing.
**

(a) How do I know whether the underlying data source supports editing? In
specific, does "class DataTable" support editing?

(b) If "calss DataTable" supports editing, are there any properites needed
to be set? (I know for sure that the settings I have make my DataGridView
not editable.)

(c) After some investigation, I found on the web, that a class needs to
implement "interface IEditable". However, I was not able to find any
documentation on this interface. It seems like it is a Java thing. Any
comments?

Thanks for your help again.
--
George
""Jeffrey Tan[MSFT]"" wrote:
Hi Fabian,

Thanks for your feedback!

By default, users can edit the contents of the current DataGridView text
box cell by typing in it or pressing F2. This puts the cell in edit mode if
all of the following conditions are met:

1. The underlying data source supports editing.
2. The DataGridView control is enabled.
3. The EditMode property value is not EditProgrammatically.
4. The ReadOnly properties of the cell, row, column, and control are all
set to false.

So your symptom is not the default behavior. You may check all the above 4
conditions to get the default editing behavior.

Hope it helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 24 '06 #6
Hi George,

Please check whether the ReadOnly property of the columns in your DataTable
is true. If yes, you could not edit the cell content in the corresponding
DataGridViewColumns in the DataGridView.

The collection used for a DataSource needn't implement the interface
IEditableObject to support editing. The collection supports editing only if
the properties in it are not readonly.

Hope this is helpful to you.

If you have any other concerns or need anything else, please don't hesitate
to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==

May 25 '06 #7
Thank you Linda. It works.
--
George
"Linda Liu [MSFT]" wrote:
Hi George,

Please check whether the ReadOnly property of the columns in your DataTable
is true. If yes, you could not edit the cell content in the corresponding
DataGridViewColumns in the DataGridView.

The collection used for a DataSource needn't implement the interface
IEditableObject to support editing. The collection supports editing only if
the properties in it are not readonly.

Hope this is helpful to you.

If you have any other concerns or need anything else, please don't hesitate
to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==

May 25 '06 #8
I am glad we finally resolved your problem. If you need further help,
please feel free to post. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 26 '06 #9

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

Similar topics

2
4843
by: Angel | last post by:
The Winform datagrid I'm working is already displaying data from a datatable. How can I add columns to that datagrid? I know (or at least I think I know) how to add the tableStyle and...
2
2677
by: Wayne Gibson | last post by:
Hi, I'm using the DataGridViewTextBoxColumn and I'm trying to find a way to detect when the a key is pressed whilst it is being edited. But there doesn't appear to be any events for this.. So...
0
1035
by: Matthew | last post by:
I have a SQLDataSource object declared in my ASPX page. <asp:SqlDataSource ID="SqlDataSource1" runat="server" etc.. etc.. /> I pipe that query into a GridView, but I also want to populate the...
6
50384
by: George | last post by:
Hi, I have been encountering a refresh problem with DataGridView, which is bound to a DataTable. When I make updates (Add, Delete, update) to the DataGridView, everything flow nicely to...
1
6015
by: jobs | last post by:
The below always results in an empty table, when I know the Gridview has rows. Dim dataTable As DataTable = CType(ChargeGridView.DataSource, DataTable) If Not (dataTable Is Nothing) Then ...
2
286
by: rmgalante | last post by:
I've had troubles with my DataGridView objects in that it is often difficult to make columns such as key columns invisible. These DataGridViews use a BindingList as a datasource, which is loaded...
1
2770
by: weird0 | last post by:
I am assigning an arrlist to the datasource property of the datagridview. In short, i want to update the datagridview. But the moment, i assign it. The application crashes. It does not display the...
11
76030
by: dave18 | last post by:
Hello all! I found a solution to my original question, but there's still so much I don't understand about it, I thought I'd give this forum a try. At the very least, maybe it will help someone...
1
9265
by: msgjunkie | last post by:
I have 3 related tables in a DataSet - Customers, Products and Orders. I am trying to create an "editable" DataGridView which, ideally, will contain columns from all the tables. I have tried...
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7009
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
7178
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,...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.