472,794 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 software developers and data experts.

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 6995
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.