datagrid source

  • Thread starter Thread starter Maarten
  • Start date Start date
M

Maarten

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.
 
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.String"));
dt.Columns.Add("Country".Type.GetType("System.String"));
dt.Rows.Add(dt.NewRow());
dt.Rows.[0][0]="Maarten";
dt.Rows.[0][1]="Belgie";
dataGrid1.Datasource = dt;
///
I hope this helps?

Cor
 
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
 
Thank you,for the reply's it works fine,
indeed is simple, but you have to know.

kind regards Maarten.
 
Back
Top