473,473 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with Windows DataGrid and DataBinding (Urgent)

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

Similar topics

4
by: CGuy | last post by:
Hi, I have an ASPX page which has a datagrid and this datagrid is bound to a Custom Collection. sample code this.DataGrid1.DataSource = UserManager.Users; this.DataGrid1.DataBind();
0
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a...
6
by: VB Programmer | last post by:
I have an itemtemplate in a datagrid. I'm trying to set it's value based on data. Having no trouble with the textbox. But, how do I do the same thing for a dropdownlist???? <ItemTemplate>...
4
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a...
2
by: momo | last post by:
Hello Guys, I have a bit of a problem, I created a Dll called SecureQueryStringDll.dll and I had the dll put bin folder of my application first and it did not work so I then put it in the bin...
2
by: Mark B | last post by:
I have a Datagrid working fine, outputting: Group Most Popular Product Code -------- ------------------------------- Earth.New Zealand 32 Earth.New Zealand
7
by: Mark B | last post by:
Can someone write some VB.Net example code for me that does this: 1) Creates a gridview control with the results of a SQL stored procedure that has 1 parameter (text) 2) Adds an extra column...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.