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

Help with Windows DataGrid and DataBinding (Urgent)

P: n/a
Hello all,
I'm trying to display a dataset into a datagrid and format the datagrid
columns but I'm having a hard time with it. I've tried the MSDN examples but
they don't seem to work.

Basically, what I want to do is that, on a button click, the dataset fills
up dynamically, binds to the datagrid, and displays the data. This is my
code:

mySql = "select itemID, OrderDate " +
"from ClientTrans where " +
"clientID = " + txtClientID.Text;
DBConnection DBConn = new DBConnection("SQLServer", mySql);
DataSet DSMyTrans = DBConn.Connection();

//I use either one of the following two for the databinding
//DGOrders.DataSource = MyTransDS.Tables["MyTable"].DefaultView;
//DGOrders.SetDataBinding(DSMyTrans, "");

I only need some way to format the columns in the datagrid (column width,
headertext, etc...) and I've searched through MSDN but to no avail. I've
tried TableStyles:
DataGridTableStyle myTS = new DataGridTableStyle();
ts1.MappingName = "Clients";
DataGridBoolColumn myDataCol = new DataGridBoolColumn();
myDataCol.HeaderText = "From Date";
myDataCol.MappingName = "Current";

ts1.GridColumnStyles.Add(myDataCol);
DGOrders.TableStyles.Add(ts1);

but nothing happens.
Are there any links that show how to format datagrids (from the dataset
fill)?

John
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
John,

Well, if you cut and pasted your code then I guess you're not using the
right variable. First you're using ' myTS ' and then you're referring to '
ts1 ' in the next line of code.

DataGridTableStyle myTS = new DataGridTableStyle();
ts1.MappingName = "Clients";

Could that be the problem?

Regards, Jim

"John" <None> schreef in bericht
news:%2****************@tk2msftngp13.phx.gbl...
Hello all,
I'm trying to display a dataset into a datagrid and format the datagrid
columns but I'm having a hard time with it. I've tried the MSDN examples but they don't seem to work.

Basically, what I want to do is that, on a button click, the dataset fills
up dynamically, binds to the datagrid, and displays the data. This is my
code:

mySql = "select itemID, OrderDate " +
"from ClientTrans where " +
"clientID = " + txtClientID.Text;
DBConnection DBConn = new DBConnection("SQLServer", mySql);
DataSet DSMyTrans = DBConn.Connection();

//I use either one of the following two for the databinding
//DGOrders.DataSource = MyTransDS.Tables["MyTable"].DefaultView;
//DGOrders.SetDataBinding(DSMyTrans, "");

I only need some way to format the columns in the datagrid (column width,
headertext, etc...) and I've searched through MSDN but to no avail. I've
tried TableStyles:
DataGridTableStyle myTS = new DataGridTableStyle();
ts1.MappingName = "Clients";
DataGridBoolColumn myDataCol = new DataGridBoolColumn();
myDataCol.HeaderText = "From Date";
myDataCol.MappingName = "Current";

ts1.GridColumnStyles.Add(myDataCol);
DGOrders.TableStyles.Add(ts1);

but nothing happens.
Are there any links that show how to format datagrids (from the dataset
fill)?

John

Nov 13 '05 #2

P: n/a
What sort of application is that? Windows Form? Web Form? What is in your
DBConnection class?

"John" <None> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hello all,
I'm trying to display a dataset into a datagrid and format the datagrid
columns but I'm having a hard time with it. I've tried the MSDN examples but they don't seem to work.

Basically, what I want to do is that, on a button click, the dataset fills
up dynamically, binds to the datagrid, and displays the data. This is my
code:

mySql = "select itemID, OrderDate " +
"from ClientTrans where " +
"clientID = " + txtClientID.Text;
DBConnection DBConn = new DBConnection("SQLServer", mySql);
DataSet DSMyTrans = DBConn.Connection();

//I use either one of the following two for the databinding
//DGOrders.DataSource = MyTransDS.Tables["MyTable"].DefaultView;
//DGOrders.SetDataBinding(DSMyTrans, "");

I only need some way to format the columns in the datagrid (column width,
headertext, etc...) and I've searched through MSDN but to no avail. I've
tried TableStyles:
DataGridTableStyle myTS = new DataGridTableStyle();
ts1.MappingName = "Clients";
DataGridBoolColumn myDataCol = new DataGridBoolColumn();
myDataCol.HeaderText = "From Date";
myDataCol.MappingName = "Current";

ts1.GridColumnStyles.Add(myDataCol);
DGOrders.TableStyles.Add(ts1);

but nothing happens.
Are there any links that show how to format datagrids (from the dataset
fill)?

John

Nov 13 '05 #3

P: n/a
Sorry. Since I was in hurry, I made that mistake.
Here's the code for the datagrid in the Windows form:

string mySql;
mySql = "select itemID " +
"from ClientTrans where " +
"clientID = " + txtClientID.Text;
DataSet DSMyTrans = new DataSet();
SqlConnection SQLConn = new SqlConnection("Data Source=localhost; Integrated
Security=SSPI;" +
"Initial Catalog=invoicing");
SqlDataAdapter MyDataAdapterClients = new SqlDataAdapter (mySql, SQLConn);
MyDataAdapterClients.TableMappings.Add("Table","My Table");
MyDataAdapterClients.Fill(DSMyTrans);
DGOrders.DataSource = DSMyTrans.Tables["MyTable"].DefaultView;
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "Clients";
DataGridBoolColumn myDataCol = new DataGridBoolColumn();
myDataCol.HeaderText = "From Date";
myDataCol.MappingName = "Current";
ts1.GridColumnStyles.Add(myDataCol);
DGOrders.TableStyles.Add(ts1);

I can see the data in the datagrid but I would like to change the different
column properties (the headertext, column width, etc...) dyamically? I've
tried tons of way to change the column header text but nothing happens.
Thanks,
John
Nov 13 '05 #4

P: n/a
It's a Windows form.
Here's the code with the connection..

string mySql;
mySql = "select itemID " +
"from ClientTrans where " +
"clientID = " + txtClientID.Text;
DataSet DSMyTrans = new DataSet();
SqlConnection SQLConn = new SqlConnection("Data Source=localhost; Integrated
Security=SSPI;" +
"Initial Catalog=invoicing");
SqlDataAdapter MyDataAdapterClients = new SqlDataAdapter (mySql, SQLConn);
MyDataAdapterClients.TableMappings.Add("Table","My Table");
MyDataAdapterClients.Fill(DSMyTrans);
DGOrders.DataSource = DSMyTrans.Tables["MyTable"].DefaultView;
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "Clients";
DataGridBoolColumn myDataCol = new DataGridBoolColumn();
myDataCol.HeaderText = "From Date";
myDataCol.MappingName = "Current";
ts1.GridColumnStyles.Add(myDataCol);
DGOrders.TableStyles.Add(ts1);

Thanks,
John

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:uX**************@TK2MSFTNGP10.phx.gbl...
What sort of application is that? Windows Form? Web Form? What is in your
DBConnection class?

"John" <None> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hello all,
I'm trying to display a dataset into a datagrid and format the datagrid
columns but I'm having a hard time with it. I've tried the MSDN examples

but
they don't seem to work.

Basically, what I want to do is that, on a button click, the dataset fills up dynamically, binds to the datagrid, and displays the data. This is my
code:

mySql = "select itemID, OrderDate " +
"from ClientTrans where " +
"clientID = " + txtClientID.Text;
DBConnection DBConn = new DBConnection("SQLServer", mySql);
DataSet DSMyTrans = DBConn.Connection();

//I use either one of the following two for the databinding
//DGOrders.DataSource = MyTransDS.Tables["MyTable"].DefaultView;
//DGOrders.SetDataBinding(DSMyTrans, "");

I only need some way to format the columns in the datagrid (column width, headertext, etc...) and I've searched through MSDN but to no avail. I've
tried TableStyles:
DataGridTableStyle myTS = new DataGridTableStyle();
ts1.MappingName = "Clients";
DataGridBoolColumn myDataCol = new DataGridBoolColumn();
myDataCol.HeaderText = "From Date";
myDataCol.MappingName = "Current";

ts1.GridColumnStyles.Add(myDataCol);
DGOrders.TableStyles.Add(ts1);

but nothing happens.
Are there any links that show how to format datagrids (from the dataset
fill)?

John


Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.