Hide column datagrid

G

Guest

Hi i want hide column datagrid,my code is:

Dim cn As New SqlCeConnection(cs)
Dim commandBuilder As SqlCeCommandBuilder
sqlDA = New SqlCeDataAdapter("SELECT * FROM ANAGRAFICA WHERE COGNOME
like '%" & TxtCerca.Text & "%' or NOME like '%" & TxtCerca.Text & "%'", cn)
commandBuilder = New SqlCeCommandBuilder(sqlDA)
sqlDS = New DataSet
sqlDA.Fill(sqlDS)
GrdCerca.DataSource = sqlDS.Tables(0)

I want hide column ID and column Note i try but not resolve problem.

Can you help me?

many thank's

Raffaele
 
I

Ilya Tumanov [MS]

E

Earl

Thank you Ilya. Very helpful information!

Ilya Tumanov said:
This property does work as described in documentation.

The difference is in CF's DataGrid (and some classes in
System.ComponentModel) which basically does not pay attention to this
property.



Anyway, I understand it might be tough to move from desktop to CF, it
seems so limited, even crippled, at first. :)

I hope it'll pass after a while, just like in this case:
http://www.mperfect.net/cfBcl/ J



Please see sample below on how to hide column in the DataGrid (works on
both CF and desktop), does not matter which data source is used.



It also "refereeing to the table by index number" just fine.

If you meant something different, please explain and/or provide code
sample, most likely there's another way to do it.



Best regards,



Ilya


This posting is provided "AS IS" with no warranties, and confers no
rights.



*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).

using System;

using System.Drawing;

using System.Collections;

using System.Windows.Forms;

using System.Data;

namespace DataSetGrid

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class Form1 : System.Windows.Forms.Form

{

private System.Windows.Forms.DataGrid dataGrid1;

private System.Windows.Forms.MainMenu mainMenu1;

private System.Windows.Forms.Button button1;

private System.Windows.Forms.MainMenu mainMenu2;

private System.Windows.Forms.MenuItem menuItem1;

private System.Windows.Forms.Button button2;

private DataSet ds;

public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.mainMenu1 = new System.Windows.Forms.MainMenu();

this.dataGrid1 = new System.Windows.Forms.DataGrid();

this.button1 = new System.Windows.Forms.Button();

this.mainMenu2 = new System.Windows.Forms.MainMenu();

this.menuItem1 = new System.Windows.Forms.MenuItem();

this.button2 = new System.Windows.Forms.Button();

//

// dataGrid1

//

this.dataGrid1.Size = new System.Drawing.Size(240, 200);

this.dataGrid1.Text = "dataGrid1";

//

// button1

//

this.button1.Location = new System.Drawing.Point(160, 224);

this.button1.Text = "Hide ID";

this.button1.Click += new System.EventHandler(this.button1_Click);

//

// mainMenu2

//

this.mainMenu2.MenuItems.Add(this.menuItem1);

//

// menuItem1

//

this.menuItem1.Text = "Quit";

this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);

//

// button2

//

this.button2.Location = new System.Drawing.Point(8, 224);

this.button2.Text = "Reset";

this.button2.Click += new System.EventHandler(this.button2_Click);

//

// Form1

//

this.Controls.Add(this.button2);

this.Controls.Add(this.button1);

this.Controls.Add(this.dataGrid1);

this.Menu = this.mainMenu2;

this.Text = "Form1";

this.Load += new System.EventHandler(this.Form1_Load);

}

#endregion

/// <summary>

/// The main entry point for the application.

/// </summary>

static void Main()

{

Application.Run(new Form1());

}

private void Form1_Load(object sender, System.EventArgs e)

{

ds = new DataSet();

ds.Tables.Add(new DataTable("Table1"));

ds.Tables[0].Columns.Add("ID", typeof(int));

ds.Tables[0].Columns.Add("SomeData", typeof(string));

ds.Tables[0].Rows.Add(new object[] {1, "One"});

ds.Tables[0].Rows.Add(new object[] {2, "Two"});

this.dataGrid1.DataSource = this.ds.Tables[0];

}

private void menuItem1_Click(object sender, System.EventArgs e)

{

this.Close();

}

private void button1_Click(object sender, System.EventArgs e)

{

this.dataGrid1.TableStyles.Clear();

DataGridTableStyle ts;

DataGridColumnStyle cs;

ts = new DataGridTableStyle();

ts.MappingName = this.ds.Tables[0].TableName;

cs = new DataGridTextBoxColumn();

cs.HeaderText = cs.MappingName = this.ds.Tables[0].Columns[0].ColumnName;

cs.Width = 0; // Hide this column.

ts.GridColumnStyles.Add(cs);

cs = new DataGridTextBoxColumn();

cs.HeaderText = cs.MappingName = this.ds.Tables[0].Columns[1].ColumnName;

cs.Width = 50;

ts.GridColumnStyles.Add(cs);

this.dataGrid1.TableStyles.Add(ts);

}

private void button2_Click(object sender, System.EventArgs e)

{

this.dataGrid1.TableStyles.Clear();

}

}

}


Earl said:
That's quite the duplicitous response. As you are well aware, it does not
work in the same manner as it works on the full framework. With the full
framework, you can refer to the table by index number, but not in CF. I
guess MS would call that working "properly", as Bill Clinton wants the
definition of "the"...

As I said, MS crippled CF by removing the
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top