Click here to Skip to main content
15,893,814 members
Home / Discussions / C#
   

C#

 
GeneralRich Text Box Pin
naresh_pandey1324-Mar-04 18:51
naresh_pandey1324-Mar-04 18:51 
GeneralSmart Build Pin
blackthunder00124-Mar-04 18:09
blackthunder00124-Mar-04 18:09 
GeneralRe: Smart Build Pin
Heath Stewart24-Mar-04 20:11
protectorHeath Stewart24-Mar-04 20:11 
GeneralRe: Smart Build Pin
blackthunder00124-Mar-04 23:42
blackthunder00124-Mar-04 23:42 
GeneralRe: Smart Build Pin
Heath Stewart25-Mar-04 4:02
protectorHeath Stewart25-Mar-04 4:02 
GeneralDataGrid Control Question Pin
DougW4824-Mar-04 16:54
DougW4824-Mar-04 16:54 
GeneralRe: DataGrid Control Question Pin
ian mariano24-Mar-04 17:28
ian mariano24-Mar-04 17:28 
GeneralRe: DataGrid Control Question Pin
Heath Stewart24-Mar-04 17:31
protectorHeath Stewart24-Mar-04 17:31 
The code that uses pre-existing data sources is what you need. The DataGrid - without overriding practically everything about it - is a data-bound control. If you use it for data entry, you must get the data from it somehow. You can do this by retrieving the DataSource value, which can be anything that implements IList or IListSource (like a DataSet, ArrayList, etc.).

Nothing says that data has to contain data initially, though. The easiest example is to use a DataSet, which you can - through code or by creating a typed DataSet - define a table and columns. In your DataGrid, set the DataSource to the empty DataSet instance, the DataMember to the name of the DataTable within the DataSet and you're basically done. You'll find that you'll have more control over the layout if you use the DataGrid.TableStyles property to add a corresponding DataGridTableStyle with various (8 in your case) DataGridColumnStyles. The documentation in the .NET Framework SDK for any one of those 3 aforementioned properties and classes will have an example (same example, IIRC).

You could also use an ArrayList or any other type of list with a list of classes that define properties and bind your DataGrid in the same way. The problem is this can be difficult if you have no initial data since the DataGrid wouldn't know how to construct your data source.

When the DataGrid is bound - even to an empty data source - rows can be added like you want. With a data source, the DataGrid can't add rows to anything because it has nothing to add them to. Give it a data source (again, I recommend a DataSet) and now it has something to modify since it's just a view on the data source.

 

Microsoft MVP, Visual C#
My Articles
Questiongetting mouse position? Pin
azusakt24-Mar-04 16:29
azusakt24-Mar-04 16:29 
AnswerRe: getting mouse position? Pin
Heath Stewart24-Mar-04 17:24
protectorHeath Stewart24-Mar-04 17:24 
QuestionHow can I save an icon? Pin
Flack24-Mar-04 14:40
Flack24-Mar-04 14:40 
AnswerRe: How can I save an icon? Pin
Heath Stewart24-Mar-04 17:21
protectorHeath Stewart24-Mar-04 17:21 
GeneralCapturing ListView scrollbar events Pin
chuck05324-Mar-04 10:45
chuck05324-Mar-04 10:45 
GeneralRe: Capturing ListView scrollbar events Pin
Heath Stewart24-Mar-04 11:24
protectorHeath Stewart24-Mar-04 11:24 
GeneralTray Icon Pin
RickZ24-Mar-04 10:34
RickZ24-Mar-04 10:34 
GeneralRe: Tray Icon Pin
Dave Kreskowiak24-Mar-04 11:08
mveDave Kreskowiak24-Mar-04 11:08 
GeneralRe: Tray Icon Pin
SapiensBwG26-Mar-04 5:41
SapiensBwG26-Mar-04 5:41 
GeneralAssembly - from Unmanaged Pin
Kant24-Mar-04 10:28
Kant24-Mar-04 10:28 
GeneralRe: Assembly - from Unmanaged Pin
Dave Kreskowiak24-Mar-04 10:33
mveDave Kreskowiak24-Mar-04 10:33 
GeneralRe: Assembly - from Unmanaged Pin
Kant24-Mar-04 11:07
Kant24-Mar-04 11:07 
GeneralRe: Assembly - from Unmanaged Pin
Heath Stewart24-Mar-04 11:22
protectorHeath Stewart24-Mar-04 11:22 
GeneralRe: Assembly - from Unmanaged Pin
Jeremy Kimball25-Mar-04 6:16
Jeremy Kimball25-Mar-04 6:16 
GeneralRe: Assembly - from Unmanaged Pin
Heath Stewart25-Mar-04 8:08
protectorHeath Stewart25-Mar-04 8:08 
GeneralRe: Assembly - from Unmanaged Pin
Jeremy Kimball25-Mar-04 9:05
Jeremy Kimball25-Mar-04 9:05 
GeneralRe: Assembly - from Unmanaged Pin
Heath Stewart25-Mar-04 9:35
protectorHeath Stewart25-Mar-04 9:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.