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

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 34169
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
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
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
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
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
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
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
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
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
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
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.