By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,201 Members | 922 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,201 IT Pros & Developers. It's quick & easy.

Can the WinForms DataGrid be used without ADO.Net?

P: n/a
I am just getting into the WinForms data grid, and just about everything I
am seeing on it seems to say that the grid must be bound to an ADO.Net
dataset. I want to use the grid as a simple unbound grid-- all I want to do
is write to the grid, read from it, and allow the user to enter text in
particular cells.

Is the WinForms datagrid a viable candidate for this sort of work? If it is,
can you recommend a resource to help me get up to speed using it as a
simple, unbound grid? If it isn't a viable candidate, can you recommend a
third party grid that would be appropriate for this use?

Thanks.

--
Dave Veeneman
da****@nospam.com
(actual domain is my last name)
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Dave Veeneman" <no****@nospam.com> wrote in message
<snip>
I want to use the grid as a simple unbound grid-- all I want to do
is write to the grid, read from it, and allow the user to enter text in particular cells.


AFAIK, the DataGrid has to be bound to have any functionality.
However, you can create an empty DataTable that takes only
strings and bind to that. I put some code below that sets that up.
--
Michael Mayer
mr*****@charter.net
My CSharp page: http://www.mag37.com/csharp/
DataTable NewTable (int cols, int rows)
{
DataTable dt = new DataTable();
for (int c = 0; c < cols; c++)
{
dt.Columns.Add(new DataColumn("", typeof(string)));
}
for (int r = 0; r < rows; r++)
{
DataRow dr = dt.NewRow();
for (int c = 0; c < cols; c++)
{
dr[c] = String.Empty; // initialize with empty string.
}
dt.Rows.Add(dr);
}
return dt;
}

private System.Windows.Forms.DataGrid dataGrid1;
private DataTable dataTable;
/******** FORM CONSTRUCTOR **/
public Form1() {
InitializeComponent();
this.dataTable = NewTable(4,8);
this.dataGrid1.DataSource = this.dataTable;
// prevent adding of new rows through datagrid
CurrencyManager cm = (CurrencyManager)
this.BindingContext[dataGrid1.DataSource,
this.dataGrid1.DataMember];
((DataView)cm.List).AllowNew = false;

// now setup some values
this.dataTable.Rows[0][0] = "Hi";
this.dataTable.Rows[1][2] = "another string";
}

Nov 15 '05 #2

P: n/a
Good solution-- thanks!

--
Dave Veeneman
da****@nospam.com
(actual domain is my last name)
Nov 15 '05 #3

P: n/a
According to MS:
The following data sources are valid:

a.. A DataTable
b.. A DataView
c.. A DataSet
d.. A DataViewManager
e.. Any component that implements the IListSource interface
f.. Any component that implements the IList interface
http://msdn.microsoft.com/library/de...ourceTopic.asp

A good example can be found here:
http://www.csharpfriends.com/Article...x?articleID=81

I personally have bound a datagrid to an arraylist and to a collection
class.

Good luck!

"Dave Veeneman" <no****@nospam.com> wrote in message
news:Ol**************@TK2MSFTNGP10.phx.gbl...
I am just getting into the WinForms data grid, and just about everything I
am seeing on it seems to say that the grid must be bound to an ADO.Net
dataset. I want to use the grid as a simple unbound grid-- all I want to do is write to the grid, read from it, and allow the user to enter text in
particular cells.

Is the WinForms datagrid a viable candidate for this sort of work? If it is, can you recommend a resource to help me get up to speed using it as a
simple, unbound grid? If it isn't a viable candidate, can you recommend a
third party grid that would be appropriate for this use?

Thanks.

--
Dave Veeneman
da****@nospam.com
(actual domain is my last name)

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.