PDA

View Full Version : سوال: چگونه می توان دیتاگریدویو دینامیک ساخت



modern_amin
دوشنبه 02 خرداد 1390, 14:58 عصر
با عرض سلام و روز بخیر خدمت دوستان

کسی می تونه منو راهنمایی کنه که چگونه می تونم تو سی شارپ دیتاگریدویو دینامیک بسازیم
مثلا از از یه جا مثل تکست باکسی عدد 50 رو که خوند دیتاگرید ویو 50 ستونی بسازه؟؟

modern_amin
دوشنبه 02 خرداد 1390, 15:04 عصر
لطفا منو راهنمایی کنید؟؟؟

monire.6767
یک شنبه 28 خرداد 1391, 15:50 عصر
من هم همین مشکلو دارم

Mahmoud.Afrad
یک شنبه 28 خرداد 1391, 16:33 عصر
گریدویو از قبل وجود داره یا نه؟ اگر نه یک شئ ازش میسازی و در یک حلقه هر تعداد ستون که میخواهید رو add میکنید. مثال
DataGridView dgv = new DataGridView();
for (int i = 0; i < 50; i++)
dgv.Columns.Add(i.ToString(), i.ToString());
this.Controls.Add(dgv);

ahmadreza517
یک شنبه 28 خرداد 1391, 17:06 عصر
به نام تنها برنامه نویس هستی
سلام ,

می تونید از این استفاده کنید.


private void textBox1_TextChanged(object sender, EventArgs e)
{
dataGridView1.Rows.Clear();

InitializeDataGridView();
}

private void InitializeDataGridView()
{
if(textBox1.Text == string.Empty)
return;

// Create an unbound DataGridView by declaring a column count.
dataGridView1.ColumnCount = 1;
dataGridView1.ColumnHeadersVisible = true;

// Set the column header style.
DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();

columnHeaderStyle.BackColor = Color.Beige;
columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Bold);
dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle;

// Set the column header names.
dataGridView1.Columns[0].Name = "Name";

for(int i=0;i<Convert.ToInt32(textBox1.Text);i++)
{
dataGridView1.Rows.Add("Ahmadreza517");
}

}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
char ch = e.KeyChar;

if(char.IsDigit(ch) == false)
{
MessageBox.Show("فقط عدد وارد کنید");
e.Handled = true;
}
}