473,378 Members | 1,351 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,378 software developers and data experts.

Datagrid problem...

Hi to all,

i think, this datagrid will drive me nuts...
I have the below code and i cannot figure out what is wrong and i cannot
format
the columns in the grid.
I, for example, try to format some things in "Sender" column but this is not
happening..
Can anyone give me a shot before i jump out of the window ??

thanks a lot for any help!
anthonyb


SqlConnection cnn = ...
cnn.Open();
SqlCommand cmd = new SqlCommand("Emails_FetchPending", cnn);
cmd.CommandType = CommandType.StoredProcedure;

SqlDataAdapter da = new SqlDataAdapter(cmd);
AddGridStyle();

DataSet ds = new DataSet();
da.Fill(ds, "MyTable");
gridPendings.DataSource = ds;
gridPendings.DataMember = "MyTable";
cnn.Close();

private void AddGridStyle()
{
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = "MyTable";
DataGridTextBoxColumn sender = new DataGridTextBoxColumn();
sender.MappingName = "Sender";
sender.HeaderText = "anthonyb";
ts.GridColumnStyles.Add(sender);
grid.TableStyles.Add(ts);
}
Nov 15 '05 #1
7 1395
Datagrids aren't what I know most about, but shouldn't you have a
gridPendings.DataBind();
to fill the datagrid with the dataset data?
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #2

"Morten Wennevik" <mo************@hotmail.com> wrote in message
news:oprvk82j0bge0n9a@localhost...
Datagrids aren't what I know most about, but shouldn't you have a
gridPendings.DataBind();
to fill the datagrid with the dataset data?
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

But i use :
DataSet ds = new DataSet();
da.Fill(ds, "MyTable");

What is wrong with that ?
Nov 15 '05 #3
That fills the dataset, but it doesn't fill the datagrid. You only tell
the datagrid that the datasource is ds, but you need to call DataBind() to
transfer data to the grid. I think.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #4
Works for me. Only noticed one error in the AddGridStyle function:

When loading the DataAdapter and setting the DataSource you reference
gridPendings...

gridPendings.DataSource = ds;
gridPendings.DataMember = "MyTable";

But in the AddGridStyle function, you reference a different grid...

grid.TableStyles.Add(ts);
If that's not the issue try playing with the TableStyle.MappingName. I've
had issues with this, but can't document it as a bug. I now use the same
string for all my table names. It seems resistant to change!

HTH,
Eric Cadwell
http://www.origincontrols.com
"Anthony Boudouvas" <an******@mediatel.gr> wrote in message
news:O3**************@tk2msftngp13.phx.gbl...
The grid displays correctly the data, but in an incorrect way...
Thanks anyway!

"Morten Wennevik" <mo************@hotmail.com> wrote in message
news:oprvk9s4qcge0n9a@localhost...
That fills the dataset, but it doesn't fill the datagrid. You only tell
the datagrid that the datasource is ds, but you need to call DataBind() to transfer data to the grid. I think.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


Nov 15 '05 #5
Anthony, how exactly do you do formatting?

this works fine for me (just make sure sender.MappingName == column name in the "MyTable" table):
sender.Format = "c"; //or "$0.000" and so on...
"Anthony Boudouvas" <an******@mediatel.gr> wrote in message news:Om**************@tk2msftngp13.phx.gbl...
Hi to all,

i think, this datagrid will drive me nuts...
I have the below code and i cannot figure out what is wrong and i cannot
format
the columns in the grid.
I, for example, try to format some things in "Sender" column but this is not
happening..
Can anyone give me a shot before i jump out of the window ??

thanks a lot for any help!
anthonyb


SqlConnection cnn = ...
cnn.Open();
SqlCommand cmd = new SqlCommand("Emails_FetchPending", cnn);
cmd.CommandType = CommandType.StoredProcedure;

SqlDataAdapter da = new SqlDataAdapter(cmd);
AddGridStyle();

DataSet ds = new DataSet();
da.Fill(ds, "MyTable");
gridPendings.DataSource = ds;
gridPendings.DataMember = "MyTable";
cnn.Close();

private void AddGridStyle()
{
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = "MyTable";
DataGridTextBoxColumn sender = new DataGridTextBoxColumn();
sender.MappingName = "Sender";
sender.HeaderText = "anthonyb";
ts.GridColumnStyles.Add(sender);
grid.TableStyles.Add(ts);
}

Nov 15 '05 #6
Eric you were right, that was indeed a problem with the code,
i wasn't referring to the correct grid.
But the problem really gon away when i used something like this:
ts.GridColumnStyles.Add(SetColumnStyle("EmailID", "EmailID",
LongestField((DataSet) gridSent.DataSource, "MyTable", gridSent,
"EmailID")));

gridSent.TableStyles.Add(ts);
And imagine doing this for every column in the grid...
I have worked in the past with third-party grids for vb6 and it was very
easy.
I see that in the datagrid you have even moe control on it,
but an "Autosize" property would make more sense...

thanks again!
Nov 15 '05 #7
Yes, I think syncfusion has a good autosize table routine.

http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp

Tip 5.48. Download the demo and he has a function that loops the columns and
autosizes them all. Not sure if he handled hidden columns but that's an easy
fix.

Alternatively if you want the columns to fit the width of the grid, just
divide the (width of the grid minus the row header width) by the number of
visible columns (to hide a column set width to 0)

HTH,
Eric Cadwell
http://www.origincontrols.com
"Anthony Boudouvas" <an******@mediatel.gr> wrote in message
news:OI**************@TK2MSFTNGP11.phx.gbl...
Eric you were right, that was indeed a problem with the code,
i wasn't referring to the correct grid.
But the problem really gon away when i used something like this:
ts.GridColumnStyles.Add(SetColumnStyle("EmailID", "EmailID",
LongestField((DataSet) gridSent.DataSource, "MyTable", gridSent,
"EmailID")));

gridSent.TableStyles.Add(ts);
And imagine doing this for every column in the grid...
I have worked in the past with third-party grids for vb6 and it was very
easy.
I see that in the datagrid you have even moe control on it,
but an "Autosize" property would make more sense...

thanks again!

Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
0
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some...
5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
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: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated...
9
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ...
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...
0
by: optimizeit | last post by:
What I am attempting to do is import an Excel Workbook and display the worksheets in a datagrid dynamically. I am very close to getting this to work. I have to this point successfully imported a...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
2
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?

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.