Binding from Dataset to Datagrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • seralasu
    New Member
    • Oct 2006
    • 34

    Binding from Dataset to Datagrid

    Hi,
    I know binding to datagrid but I don't know to show some coloumns.
    Example:
    Dim adopter As New OleDbDataAdapte r("select * from IPSAVE", baglanti)
    Dim ds As DataSet = New DataSet
    adopter.Fill(ds , "IP")
    DataGrid1.DataS ource = ds.Tables("IP")

    But I don't want to change OleDbDataAdapte r("select * from IPSAVE", baglanti)
    Wiil I bind Some coloumns to datagrid.Can I change DataGrid1.DataS ource = ds.Tables("IP")
  • radcaesar
    Recognized Expert Contributor
    • Sep 2006
    • 759

    #2
    Yup U Can,

    dsSAT.Tables["Transactio ns"].Columns.Add("B alance Amount", typeof(Double)) ;
    dsSAT.Tables["Transactio ns"].Columns["Balance Amount"].Expression = "[Gross Amount] - [Amount Received]";
    dgSAT.DataSourc e =dsSAT.Tables[0];

    ;)


    Originally posted by seralasu
    Hi,
    I know binding to datagrid but I don't know to show some coloumns.
    Example:
    Dim adopter As New OleDbDataAdapte r("select * from IPSAVE", baglanti)
    Dim ds As DataSet = New DataSet
    adopter.Fill(ds , "IP")
    DataGrid1.DataS ource = ds.Tables("IP")

    But I don't want to change OleDbDataAdapte r("select * from IPSAVE", baglanti)
    Wiil I bind Some coloumns to datagrid.Can I change DataGrid1.DataS ource = ds.Tables("IP")

    Comment

    • seralasu
      New Member
      • Oct 2006
      • 34

      #3
      Originally posted by radcaesar
      Yup U Can,

      dsSAT.Tables["Transactio ns"].Columns.Add("B alance Amount", typeof(Double)) ;
      dsSAT.Tables["Transactio ns"].Columns["Balance Amount"].Expression = "[Gross Amount] - [Amount Received]";
      dgSAT.DataSourc e =dsSAT.Tables[0];

      ;)
      I don't want to use some Oledbadopter's field(Select * from IPSAVE) .I don't want to show eaxample:"IP","SubnetMa sk" ....fields. I want to show "Name" field only in Datagrid . I didn't understand your solution.

      Comment

      • pmcalenney
        New Member
        • Oct 2006
        • 8

        #4
        You need to set up a DataGridTableSt yle object on the datagrid. This object contains a DataGridColumnS tyles collection, where you can define which columns will be shown. It is a bit onerous to set up, but pretty nice once it is. This enables your bound dataset to not have to be limited to the 1 column - the dataset can contain all colums, but your datagrid.datagr idtablestyle object defines what colums to show. In your case you would only add 1 datagridcolumn to your datagridcolumn styles. You can set these up at runtime or at design time - easier at design time if you do it there.

        Comment

        • seralasu
          New Member
          • Oct 2006
          • 34

          #5
          Originally posted by pmcalenney
          You need to set up a DataGridTableSt yle object on the datagrid. This object contains a DataGridColumnS tyles collection, where you can define which columns will be shown. It is a bit onerous to set up, but pretty nice once it is. This enables your bound dataset to not have to be limited to the 1 column - the dataset can contain all colums, but your datagrid.datagr idtablestyle object defines what colums to show. In your case you would only add 1 datagridcolumn to your datagridcolumn styles. You can set these up at runtime or at design time - easier at design time if you do it there.
          Thanks your solution

          Comment

          Working...