|
C#: In my application program, i have been placed a datagridview control on the form. Now i have to show the datagridviews data in a non-scrollable mode, i.e., the datagridview's size should be vary from the data. For example, if the datagridview1 control has two records, then that control should view the two records sized only, no empty spaces should not be shown, eventhough the size of the control is increases by the data record increases thats never mind. Just i have to display datagridview in non-scrollable mode and that scroll is set to the application form. How? ---Sri's- Moved byTaylorMichaelLMVPTuesday, September 22, 2009 1:29 PMWinForms related (From:Visual C# General)
-
| | My Best Solutions Sunday, September 20, 2009 11:14 AM | Hi, I hope it will help you
private void Form3_Load(object sender, EventArgs e)
{
BindData();
}
private DataSet CreateDataSet()
{
DataTable table = new DataTable("childTable");
DataColumn column;
DataRow row;
DataSet dataset = new DataSet();
// Create first column and add to the DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "CustID";
column.AutoIncrement = true;
column.Caption = "ID";
column.ReadOnly = true;
//Unique Column
column.Unique = true;
// Add the column to the DataColumnCollection.
table.Columns.Add(column);
//// Create second column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "CustName";
column.AutoIncrement = false;
column.Caption = "Name";
column.ReadOnly = false;
column.Unique = false;
table.Columns.Add(column);
dataset.Tables.Add(table);
// Create three sets of DataRow objects,
// five rows each, and add to DataTable.
for (int i = 0; i <= 100; i++)
{
row = table.NewRow();
row["CustID"] = i;
row["CustName"] = "Item " + i;
table.Rows.Add(row);
}
return dataset;
}
DataSet dsCust;
private void BindData()
{
dsCust = CreateDataSet();
dataGridView1.DataSource = dsCust.Tables[0];
dataGridView1.ScrollBars = ScrollBars.None;
int height=dataGridView1.RowTemplate.Height * dataGridView1.Rows.Count;;
dataGridView1.Height = height;
this.Height = height;
this.AutoScroll = true;
this.HorizontalScroll.Enabled = false;
}
Best Regards,
C.Gnanadurai
-----------------------
Please mark the post as answer if it is helpfull to you - Marked As Answer byAland LiMSFT, ModeratorWednesday, September 23, 2009 6:07 AM
- Proposed As Answer byGnanadurai Wednesday, September 23, 2009 3:35 AM
-
| | Gnanadurai Tuesday, September 22, 2009 1:17 PM | Hi, using this you can disable the scroll of the datagridview. i hope it will help you.
//disable dgv scrollbar
dataGridView1.ScrollBars = ScrollBars.None;
//enable form scrollbar
this.VerticalScroll.Enabled = true;
Best Regards,
C.Gnanadurai
-----------------------
Please mark the post as answer if it is helpfull to you | | Gnanadurai Tuesday, September 22, 2009 5:15 AM | While designing time, whatever the control (with specified size) we placed on the form. At runtime also, that we specified size only displayed. But from the above my question is : the datagridview1 control should be increase for every new record i entered. i.e., All the Records in the datagridview1 control should be displayed in a single page without scrollbar. [Note: Eventhough the size (not inthe sense Memory) of the datagridview1 control increases, then the form1 window size should also be increases.]
---Sri's | | My Best Solutions Tuesday, September 22, 2009 12:43 PM | Hi Sri,
Keep in mind that a window will only grow to a maximum size that will fit on the hosting PC's desktop settings.
I would suggest a different approach: Store your data in a dataset, select only those records that you want to display, and send those records only to datagridview1. You would likely still want to keep the scrollbars on the datagridview control, though, because the data could exceed the form's size.
To resize the form, measure the size of your form with no records displayed, with one record displayed and with 2 records displayed. Pay attetion to the pattern (if you show a header on your datagridview control, you will have to account for more cases than otherwise). If you have your row height in the datagridview control set to be 'n' and you are showing 'count' rows, then you will have to increase your form's height by 'n' * 'count' (and by the header height, if you show that).
Keep in mind that you will need to store a value for your form's height with no rows, so that whenever the datagridview control is not being shown, you can easily return to your predetermined size.
I hope this helps,
Joe Avoid Sears Home Improvement | | jp2msft Tuesday, September 22, 2009 1:07 PM | Hi, I hope it will help you
private void Form3_Load(object sender, EventArgs e)
{
BindData();
}
private DataSet CreateDataSet()
{
DataTable table = new DataTable("childTable");
DataColumn column;
DataRow row;
DataSet dataset = new DataSet();
// Create first column and add to the DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "CustID";
column.AutoIncrement = true;
column.Caption = "ID";
column.ReadOnly = true;
//Unique Column
column.Unique = true;
// Add the column to the DataColumnCollection.
table.Columns.Add(column);
//// Create second column.
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "CustName";
column.AutoIncrement = false;
column.Caption = "Name";
column.ReadOnly = false;
column.Unique = false;
table.Columns.Add(column);
dataset.Tables.Add(table);
// Create three sets of DataRow objects,
// five rows each, and add to DataTable.
for (int i = 0; i <= 100; i++)
{
row = table.NewRow();
row["CustID"] = i;
row["CustName"] = "Item " + i;
table.Rows.Add(row);
}
return dataset;
}
DataSet dsCust;
private void BindData()
{
dsCust = CreateDataSet();
dataGridView1.DataSource = dsCust.Tables[0];
dataGridView1.ScrollBars = ScrollBars.None;
int height=dataGridView1.RowTemplate.Height * dataGridView1.Rows.Count;;
dataGridView1.Height = height;
this.Height = height;
this.AutoScroll = true;
this.HorizontalScroll.Enabled = false;
}
Best Regards,
C.Gnanadurai
-----------------------
Please mark the post as answer if it is helpfull to you - Marked As Answer byAland LiMSFT, ModeratorWednesday, September 23, 2009 6:07 AM
- Proposed As Answer byGnanadurai Wednesday, September 23, 2009 3:35 AM
-
| | Gnanadurai Tuesday, September 22, 2009 1:17 PM |
|