RE: listbox and Datagrid, 2 tables, and a relationship

From: Steven Cheng[MSFT] (v-schang_at_online.microsoft.com)
Date: 04/06/04


Date: Tue, 06 Apr 2004 06:35:19 GMT

Hi Mark,

I'm sorry that I haven't noticed that you're using VB.NET. As for the new
questions:
"How do I keep a column from being shown in my datagrid. It currently shows
the ProgramID, which I would like to keep behind the scenes."

You can make use of the DataGridTableStyle to format the outlooking of the
winform datagrid, you can control how many columns to display and how they
display in the certain datagrid. For detailed description, you can refer to
the following reference and samples in MSDN:
#Formatting the Windows Forms DataGrid Control in Visual Basic
http://msdn.microsoft.com/library/en-us/dv_vstechart/html/vbtchFormattingWin
dowsFormsDataGridVisualBasicPrimer.asp?frame=true

#DataGridColumnStyle Class
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwindowsformsda
tagridcolumnstyleclasstopic.asp?frame=true

As for your situation that you have three columns("ProgramID", "Data1",
"Data2" ...) and only want to display the latter twos in datagrid, you can
create a tablestyle which only contains two tablecolumns and apply it onto
the datagrid, such as below:

Protected Sub AddFormattedStyle()
   Dim tsDetail As New DataGridTableStyle()
   tsDetail.MappingName = "tbDetail"
   
   
   Dim tbcData1 As New DataGridTextBoxColumn()
   tbcData1.MappingName = "Data1"
   tbcData1.HeaderText = "Program Data1"
   
   Dim tbcData2 As New DataGridTextBoxColumn()
   tbcData2.MappingName = "Data2"
   tbcData2.HeaderText = "Program Data2"
   
   tsDetail.GridColumnStyles.Add(tbcData1)
   tsDetail.GridColumnStyles.Add(tbcData2)
   dgDetail.TableStyles.Add(tsDetail)
End Sub 'AddFormattedStyle

#The above function is apply a DataGridTableStyle onto the dgDetail
DataGrid which only show two columns(without the "ProgramID" column).

In addition, here is a webpage which can help to translate C# code into
VB.NET. I believe it will be helpful to you when you viewing C# code
sample. Thanks.

#C# to VB.NET Translator
http://authors.aspalliance.com/aldotnet/examples/translate.aspx

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx



Relevant Pages

  • Re: Extracting subsets of a DataSet
    ... Try it first with that sort on the model column commented out and see what is displayed in your datagrid. ... Regarding the application I am making, it is a Web Form, not a Windows Form. ... I have abandon the DataView idea because what I have read about DataView does not seem to be what I want. ... My goal is to display only, not modify, a subset of those rows based on user input. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Performance issue
    ... I have two queries to make and two data to display in a datagrid. ... first query and first data to display: ... a)query: the user enters some characters, the query selects the rows from ...
    (microsoft.public.sqlserver.ce)
  • Re: Problem with ComboBox
    ... Cor Ligthert [MVP] wrote: ... record from the list) the detail and datagrid will display me the ... I choose them the number on the combobox changes to a number that I ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Problem with ComboBox
    ... What VB version are you using and what complex data control, ... record from the list) the detail and datagrid will display me the ... I choose them the number on the combobox changes to a number that I ...
    (microsoft.public.dotnet.languages.vb)
  • Re: disconnected typed dataset
    ... I have had a look into the datagrid, but it only seems to display one table ... >> I am creating a multi-user db app in VB.NET 2003 which accesses a remote ... >> row (Customer/Address pair) and edit it elsewhere. ...
    (microsoft.public.dotnet.framework.adonet)