0
我想獲取索引或永久更改我的按鈕的值。 我得到了二維列表Button[,] bt;
我試圖通過bt.Indexof得到它,但它不適用於二維數組。我想永久更改值h1,這是我的數據庫中的一列。獲取索引或更改Button的值。
private void cbCinemaHall_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
grdMain.Children.Clear();
f1 = CHallObj.GetHallList();
h1 = CHallObj.halls2();
bt = new Button[h1[cbCinemaHall.SelectedIndex].GetLength(0), h1[cbCinemaHall.SelectedIndex].GetLength(1)];
double x = 0, y = 0;
int numberToTagCounter = 0;
for (int i = 0; i < bt.GetLength(0); i++)
{
int columnCounter = 0;
for (int j = 0; j < bt.GetLength(1); j++)
{
if (Convert.ToInt32(h1[cbCinemaHall.SelectedIndex][i, j]) == 0)
{ //0=wolna przestrzeń
y = i * height;
if (j == 0)
x = 0;
x += (width + 1);
}
if (Convert.ToInt32(h1[cbCinemaHall.SelectedIndex][i, j]) == 1)
{ //1=pierwsza grupa cenowa
columnCounter++;
numberToTagCounter++;
bt[i, j] = new Button();
bt[i, j].Height = height;
bt[i, j].Width = width;
bt[i, j].Content = columnCounter.ToString();
bt[i, j].Tag = numberToTagCounter;
bt[i, j].Background = Brushes.Green;
y = i * height;
if (j == 0)
x = 0;
x += (width + 1);
bt[i, j].Margin = new Thickness(x, y, 0, 0);
bt[i, j].Click += Button_Click;
//bt[i, j].Click += button_Click_1;
//bt[i, j].MouseDoubleClick += Generating_MouseDoubleClick;
}
if (Convert.ToInt32(h1[cbCinemaHall.SelectedIndex][i, j]) == 2)
{ //2=premiumqualityplaces
columnCounter++;
numberToTagCounter++;
bt[i, j] = new Button();
bt[i, j].Height = height;
bt[i, j].Width = width;
bt[i, j].Content = columnCounter.ToString();
bt[i, j].Tag = numberToTagCounter;
bt[i, j].Background = Brushes.Coral;
y = i * height;
if (j == 0)
x = 0;
x += (width + 1);
bt[i, j].Margin = new Thickness(x, y, 0, 0);
bt[i, j].Click += Button_Click;
//bt[i, j].MouseDoubleClick += Generating_MouseDoubleClick;
}
}
}
for (int i = 0; i < bt.GetLength(0); i++)
{
for (int j = 0; j < bt.GetLength(1); j++)
{
if (bt[i, j] == null)
continue; //jeśli jest zerowe pole
grdMain.Children.Add(bt[i, j]); //dodajemy miejsce
}
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
int ind = bt.Indexof
// context.SaveChanges();
}
}