Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default behavior of DataGrid ?? 1

Status
Not open for further replies.

mir23

Programmer
Oct 28, 2003
11
BE
Hello,

I have a DataView bind to a basic Datagrid with 3 columns.
At Form Initialization only the first column of the DataGrid contain info.
Whenever I fill the 2 others columns, the row is disappearing (I guess hide) from the DataGrid... this is a great default behavior, but not user friendly in the case of my client :)

Does anyone know how to simply make that DataGrid not "dynamic like" style.

This would help greatly, Many thanks,

Mir

 
If you are not specifying the schema of the grid ahead of time, that will happen.

You should create a datatable that looks like you want and then fill that table and bind it to the grid like the following:

Code:
string mConnString = "Data Source=127.0.0.1;Initial Catalog=CatalogWhatever;User ID=uid;Password=pass";
string mCmdString = "SELECT ColumnA, ColumnB, ColumnC FROM tbl_Web_ApplicationMessage";

SqlConnection mConn = new SqlConnection(mConnString);
SqlCommand mCmd = new SqlCommand(mCmdString, mConn);
SqlDataReader dr; 
      
System.Data.DataTable dt = new System.Data.DataTable("Table1");
dt.Columns.Add(new System.Data.DataColumn("Wont_Have_Value"));
dt.Columns.Add(new System.Data.DataColumn("ColumnA"));
dt.Columns.Add(new System.Data.DataColumn("ColumnB"));
dt.Columns.Add(new System.Data.DataColumn("ColumnC"));        

mConn.Open();

dr = mCmd.ExecuteReader();

while (dr.Read())
{
  System.Data.DataRow mDr = dt.NewRow();
     
  mDr["ColumnA"] = dr.GetValue(0).ToString();
  mDr["ColumnB"] = dr.GetValue(1).ToString();
  mDr["Columnc"] = dr.GetValue(2).ToString();          

  dt.Rows.Add(mDr);
}
        
dataGrid1.DataSource = dt;
            
mConn.Close();

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
Hi,
Thanks for reply,
I'm actually using a XmlDataDocument to sync between an XML file and the DataSet as following:

//Set Dataset schema
XmlTextReader xtr =New XmlTextReader(@"..\..\file.xml");
XmlDataDocument xdd= new XmlDataDocument();
DataSet ds = xdd.DataSet;
ds.ReadXmlSchema(xtr);
xtr.Close();

// Fill Dataset through the XmlDataDocument
xtr =New XmlTextReader(@"..\..\file.xml");
xdd.Load(xtr);
xtr.Close();

// Here I create the DataView with RowFilter Property
DataView dv= new DataView(ds.Tables[0]);
ds.RowFilter = "ColumnB= '' OR ColumnC=''";

//Then I bind to the Datagrid
dg.DataSource= dv;
--------------
Whenever I fill the ColumnB and ColumnC of a particular row, it keep on disappearing.
If I bind the DataGrid straight from the DataTable, it works fine, the problem seems to be the row filtering option.

Thanks for your help...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top