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

datagrid source

P: n/a
hi all,

i want to fill a datagrid with some variables.
i don't want it to connect with a database.

can someone please give me some code to make this work.

i think i have to make a dataset first
then a data table and then fill this with datarows

but how do i do this 3 steps
i've been looking on the internet, but there are only examples to fill it
from a database.

thanks Maarten.
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Maarten,

You need a datatable for that, it is so simple that I type it in this
message so watch typos.

\\\
DataTable dt = new DataTable("Maarten");
dt.Columns.Add("FirstName",Type.GetType("System.St ring"));
dt.Columns.Add("Country".Type.GetType("System.Stri ng"));
dt.Rows.Add(dt.NewRow());
dt.Rows.[0][0]="Maarten";
dt.Rows.[0][1]="Belgie";
dataGrid1.Datasource = dt;
///
I hope this helps?

Cor
Nov 16 '05 #2

P: n/a
Hi Maarten
Here is part of some code I wrote. it also show how to remove rows , hope
it helps
private void button1_Click(object sender, System.EventArgs e)
{
myset = new DataSet();
mytable = new DataTable("trial");
mycolumn = new DataColumn("col1" , Type.GetType("System.Decimal"));
mycolumn.AllowDBNull = true;
mytable.Columns.Add(mycolumn);
DataRow myrow = mytable.NewRow();
myrow["col1"]= 11.1;
mytable.Rows.Add(myrow);
mytable.Rows.Add(new object[]{12.2});
mytable.Rows.Add(new object[]{14.7});
myset.Tables.Add(mytable);
DataRowCollection r = mytable.Rows;

string k ;

k = myset.GetXml();

/*foreach (DataRow k in r)
{
if (k.RowState == System.Data.DataRowState.Deleted){}
else
{
mytable.Rows.Remove(k);
}
}*/
for( int idx = 0; idx < r.Count; idx++ )
{
DataRow row = mytable.Rows[ idx ];
if( row.RowState == DataRowState.Deleted )
{
if( row[ mycolumn, DataRowVersion.Original ].ToString()== "12.2" )
{
r.RemoveAt( idx );
idx--;
}
}
else
{
if( row[ mycolumn].ToString() == "12.2" )
{
r.RemoveAt( idx );
idx--;
}
}
}

myset.WriteXml("c:\\temp.xml ", System.Data.XmlWriteMode.DiffGram);
}

private void Form1_Load(object sender, System.EventArgs e)
{
report = new CrystalReport1();
//this.oleDbDataAdapter1.Fill(dataSet11.Tables[0]);
report.SetDataSource(dataSet11);
this.crystalReportViewer1.ReportSource = report;
int i=0;
int j=0;
bool k=false;
k = !k;
i = j+3;
MessageBox.Show(k.ToString());
}

}
Mohamed M .Mahfouz
Developer Support Engineer
ITWorx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #3

P: n/a
Thank you,for the reply's it works fine,
indeed is simple, but you have to know.

kind regards Maarten.

"Maarten" <gu******@hotmail.com> schreef in bericht
news:42***********************@news.skynet.be...
hi all,

i want to fill a datagrid with some variables.
i don't want it to connect with a database.

can someone please give me some code to make this work.

i think i have to make a dataset first
then a data table and then fill this with datarows

but how do i do this 3 steps
i've been looking on the internet, but there are only examples to fill it
from a database.

thanks Maarten.

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.