PDA

View Full Version : پیمایش کل رکورد های یک جدول



matrix3749
سه شنبه 13 اسفند 1392, 20:37 عصر
سلام ببخشید دوستان من میخام یه دیتاگریدویو توی سی شارپ بسازم با تعداد معلوم سطر و ستون و بعد یک سری اطلاعات وارد آن کنم وبعد از یه خانه شروع کرده و با حرکات به سمت بالا و پایین و چپ و راست (حرکت ضربدری ممنوع) پیش برم تا به بن بست بخورم بعد برگردم و از یه راه دیگه برم تا اینکه کل رکورد ها را بازیابی کنم.
با تشکر ممنونم

مهرداد صفا
سه شنبه 13 اسفند 1392, 21:09 عصر
سلام.
به این صورت؟


//بسم الله الرحمن الرحیم
//اللهم صل علی محمد و آل محمد

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
dataGridView1.Size = this.Size;
dataGridView1.Location = new Point(0, 0);
dataGridView1.RowCount = 10;
dataGridView1.ColumnCount = 10;

int c = 0;
int direction = 1;
int rc = 0;
int cc = 0;
while (c < dataGridView1.RowCount * dataGridView1.ColumnCount)
{

dataGridView1[cc, rc].Value = c++;

cc += direction;
if(cc==dataGridView1.ColumnCount || cc<0)
{
direction *= -1;
rc += 1;
cc += direction;
}

}
}
}
}