PDA

View Full Version : نمایش آرایه دو بعدی در DataGridView



Xcalivorse
پنج شنبه 10 مرداد 1387, 11:55 صبح
با سلام. دوستان می خواستم بدونم چه طوری میشه یک آرایه دوبعدی رو در یک DataGridView نمایش داد. من خاصیت DataSource گرید ویو رو با نام آرایه ست می کنم ولی جواب نمیده.
با تشکر.

Xcalivorse
پنج شنبه 10 مرداد 1387, 13:19 عصر
من وقتی این کارو میکنم Error میده. در ضمن وقتی آرایه یک بعدی رو هم وصل می کنم فقط طول عناصرش در ردیف هی نمایش داده میشه.

نهمنهح
پنج شنبه 10 مرداد 1387, 14:21 عصر
آرایه یک بعدی

private void button1_Click(object sender, EventArgs e)
{
// Create an unbound DataGridView by declaring a column count.
dataGridView1.ColumnCount = 4;
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 = "Recipe";
dataGridView1.Columns[1].Name = "Category";
dataGridView1.Columns[2].Name = "Main Ingredients";
dataGridView1.Columns[3].Name = "Rating";

// Populate the rows.
string[] row1 = new string[] { "Meatloaf", "Main Dish", "ground beef",
"**" };
string[] row2 = new string[] { "Key Lime Pie", "Dessert",
"lime juice, evaporated milk", "****" };
string[] row3 = new string[] { "Orange-Salsa Pork Chops", "Main Dish",
"pork chops, salsa, orange juice", "****" };
string[] row4 = new string[] { "Black Bean and Rice Salad", "Salad",
"black beans, brown rice", "****" };
string[] row5 = new string[] { "Chocolate Cheesecake", "Dessert",
"cream cheese", "***" };
string[] row6 = new string[] { "Black Bean Dip", "Appetizer",
"black beans, sour cream", "***" };
object[] rows = new object[] { row1, row2, row3, row4, row5, row6 };

foreach (string[] rowArray in rows)
{
dataGridView1.Rows.Add(rowArray);
}

}

دو بعدیشو نمیدونم

نهمنهح
پنج شنبه 10 مرداد 1387, 14:40 عصر
اینم دو بعدیش:

private void button1_Click(object sender, EventArgs e)
{
dataGridView1.ColumnCount = 9;
string[,] str1 = new string[3, 3];
str1[0, 0] = "mohsen";
str1[0, 1] = "zamani";
str1[0, 2] = "is";
str1[1, 0] = "a";
str1[1, 1] = "good";
str1[1, 2] = "boy";
str1[2, 0] = "is";
str1[2, 1] = "not";
str1[2, 2] = ".";
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
dataGridView1.Rows.Add(str1[i,j]);
}

}

}