473,407 Members | 2,326 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,407 software developers and data experts.

datagrid source

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
3 1677
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
3
by: PeterZ | last post by:
G'day, After doing much searching and pinching bits of ideas from here there and everywhere I came up with a fairly 'clean' solution of including a comboBox into a dataGrid column. You can...
2
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
4
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
1
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .....
4
by: Jan Nielsen | last post by:
Hi all I'm a former Access developer who would like to implement a many-to-many relation in about the same way you do in Access: With a subform and a combo box. Is it possible to use a...
13
by: pmcguire | last post by:
I have a DataGrid control for which I have also created several new extended DataGridColumnStyles. They behave pretty nicely, but I can't figure out how to implement Selected Item formatting for...
0
by: Familjen Karlsson | last post by:
Hi I have downloaded some code and tried it and nothing happens with the datagrid. Explain what is wrong and what I have to do please. I have tried to Import the namespace Hamster and it didn't...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.