|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
setting datagrid column widths in code?Hello,
I have a one datagrid that will be based on different datatables. One datatable may have 7 columns, another 15... With the tables that have more columns, I have been manually dragging column widths to narrow them. I want to record these widths so I can reapply them when I bind the datagrid to the table with 15 columns. I have searched around for articles on this and saw some that talked about datagrid.TableStyle.GridColumnStyle something, but on intellisense of my datagrid I got TableStyles and no GridColumnStyles. I would be very grateful if someone could set me straight on how I can retrieve and set column widths for a datagrid from code. Do I need to use a dataview maybe to do this? Thanks, Rich Rich wrote:
Show quoteHide quote > Hello, I can tell you how to do the GridColumnStyle (it's > > I have a one datagrid that will be based on different datatables. One > datatable may have 7 columns, another 15... With the tables that have more > columns, I have been manually dragging column widths to narrow them. I want > to record these widths so I can reapply them when I bind the datagrid to the > table with 15 columns. I have searched around for articles on this and saw > some that talked about datagrid.TableStyle.GridColumnStyle something, but on > intellisense of my datagrid I got TableStyles and no GridColumnStyles. I > would be very grateful if someone could set me straight on how I can retrieve > and set column widths for a datagrid from code. Do I need to use a dataview > maybe to do this? > > Thanks, > Rich datagrid.TableStyle(0).GridColumnStyle) but there is a better way. If you add one TableStyle for each of the datatables you are using the grid will change automatically depending on which datatable is bound to it. The key that seems to get missed often on doing this is to make sure the TableStyle.MappingName matches the name of the datatable. Hope this helps. Chris I am having a problem setting a table style for my datatable. How do I do
that? Dim dt As DataTable dt = Dataset1.Tables("tbl1") dt.??????? datagrid1.DataSource = dt Show quoteHide quote > > I can tell you how to do the GridColumnStyle (it's > datagrid.TableStyle(0).GridColumnStyle) but there is a better way. > > If you add one TableStyle for each of the datatables you are using the > grid will change automatically depending on which datatable is bound to > it. The key that seems to get missed often on doing this is to make > sure the TableStyle.MappingName matches the name of the datatable. > > Hope this helps. > Chris > Rich wrote:
Show quoteHide quote > I am having a problem setting a table style for my datatable. How do I do You set the tablestyle of the datagrid.> that? > > Dim dt As DataTable > dt = Dataset1.Tables("tbl1") > dt.??????? > datagrid1.DataSource = dt > > > >>I can tell you how to do the GridColumnStyle (it's >>datagrid.TableStyle(0).GridColumnStyle) but there is a better way. >> >>If you add one TableStyle for each of the datatables you are using the >>grid will change automatically depending on which datatable is bound to >>it. The key that seems to get missed often on doing this is to make >>sure the TableStyle.MappingName matches the name of the datatable. >> >>Hope this helps. >>Chris >> (doing this from memory, but you'll get the idea) 'Do this for each table Dim DT as new DataGridTableStyle DT.MappingName = "tbl1" '<--Important! 'Add one for each column you want displayed Dim Column as new DataGridTextBoxColumn Column.Width = 100 Column.DisplayName = ... 'This might be wrong property Column.MappingName = ... 'This might be wrong property DT.DataGridColumnStyle.Add(Column) Column = new DataGridTextBoxColumn Column.Width = 150 Column.DisplayName = ... 'This might be wrong property Column.MappingName = ... 'This might be wrong property DT.DataGridColumnStyle.Add(Column) DataGrid1.TableStyles.Add(DT) Dim dt As DataTable datagrid1.DataSource = Dataset1.Tables("tbl1") Hope this helps Chris Thanks. This should do the trick. I might have to tweak it a little bit.
But yes I get the idea now. Rich Show quoteHide quote "Chris" wrote: > Rich wrote: > > I am having a problem setting a table style for my datatable. How do I do > > that? > > > > Dim dt As DataTable > > dt = Dataset1.Tables("tbl1") > > dt.??????? > > datagrid1.DataSource = dt > > > > > > > >>I can tell you how to do the GridColumnStyle (it's > >>datagrid.TableStyle(0).GridColumnStyle) but there is a better way. > >> > >>If you add one TableStyle for each of the datatables you are using the > >>grid will change automatically depending on which datatable is bound to > >>it. The key that seems to get missed often on doing this is to make > >>sure the TableStyle.MappingName matches the name of the datatable. > >> > >>Hope this helps. > >>Chris > >> > > > You set the tablestyle of the datagrid. > (doing this from memory, but you'll get the idea) > > 'Do this for each table > Dim DT as new DataGridTableStyle > DT.MappingName = "tbl1" '<--Important! > > 'Add one for each column you want displayed > Dim Column as new DataGridTextBoxColumn > Column.Width = 100 > Column.DisplayName = ... 'This might be wrong property > Column.MappingName = ... 'This might be wrong property > DT.DataGridColumnStyle.Add(Column) > Column = new DataGridTextBoxColumn > Column.Width = 150 > Column.DisplayName = ... 'This might be wrong property > Column.MappingName = ... 'This might be wrong property > DT.DataGridColumnStyle.Add(Column) > > DataGrid1.TableStyles.Add(DT) > > Dim dt As DataTable > datagrid1.DataSource = Dataset1.Tables("tbl1") > > Hope this helps > Chris >
Converted a solution to VS2005 and it is complaining: Variable 'PF2' is used before it has been assi
READING EMAILS Problem with installer made in VS 2003.NET Detect Concurrent Running Instances How do I maintain paragraph numbers into a new word document Run from Server or Workstation write Override methods in Code Editor VS2005 Can we run Vb.Net Application on Apple Macintosh ? StreamReader does not read all characters... |
|||||||||||||||||||||||