Народ, помогите!!!!!
Мне надо привести к Control`у неважно какой DataGridView***Сell (ну пусть будет DataGridViewComboBoxCell)
dataGridView1.Rows[0].Cells[0] — это к Control`у
P.S. причем нельзя использовать событие EditingControlShowing, используя обработку этого события все просто,
а без него??????
Люди помогите! ОЧЕНЬ надо!
P.S. метод DataGridView.EditingControl — все время возвращает null ?!
P.S.S. Мне в наследство достался компонент (
без исходнков, а без него придется переписывать ВЕСЬ проект) который в одном из своих методов принимает в качестве параметра Control, поэтому мне конкретно нужно привести DataGridViewCell к Control`у!
Люди не дайте умереть ИДИОТОМ!!! Помогите!!!
Ведь
должно быть какоето простое
решение!!!
P.S.S.S. повторюсь,
не используя EditingControlShowing
VS2005, C#, DataGridView.
Hi 1900
1900>Мне надо привести к Control`у неважно какой DataGridView***Сell (ну пусть будет DataGridViewComboBoxCell)
1900>dataGridView1.Rows[0].Cells[0] — это к Control`у
Если меня не подводит память, то прямо никак. Потому что DataGridView***Сell не имеют в предках Control.
Так что только писать свой наследник от Control, который внутри будет держать ссылку на DataGridView***Сell и транслировать все вызовы к DataGridView***Сell.
--
С Уважением
Posted via RSDN NNTP Server 2.0
поясню мысль кодом:
using System;
using System.ComponentModel;
using System.Data;
using System.Windows.Forms;
namespace WindowsApplication1
{
class Form1 : Form
{
static void Main()
{
Application.Run(new Form1());
}
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.DataGridView dataGridView1;
public Form1()
{
InitializeComponent();
InitializeData();
}
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
components.Dispose();
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
// button1
this.button1.Location = new System.Drawing.Point(12, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "Поехали";
this.button1.Click += new System.EventHandler(this.button1_Click);
// dataGridView1
this.dataGridView1.AllowUserToAddRows = false;
this.dataGridView1.AllowUserToDeleteRows = false;
this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(12, 41);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(365, 245);
this.dataGridView1.TabIndex = 1;
// Form1
this.ClientSize = new System.Drawing.Size(389, 298);
this.Controls.Add(this.dataGridView1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Достаем Control из DataGridView";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
}
private void InitializeData()
{
DataTable dataTable = new DataTable();
dataTable.Columns.Add("column1").DataType = typeof(string);
dataTable.Columns.Add("column2").DataType = typeof(string);
dataTable.Columns.Add("column3").DataType = typeof(string);
dataTable.Rows.Add("value 1", "value 2", "value 3");
dataTable.Rows.Add("value 4", "value 5", "value 6");
dataTable.AcceptChanges();
dataGridView1.DataSource = dataTable;
}
private void button1_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedCells.Count != 1)
{
MessageBox.Show("Выберите сначала одну ячейку");
return;
}
dataGridView1.BeginEdit(true);
Control control = dataGridView1.EditingControl;
MessageBox.Show("Значение в ячейке: " + control.Text);
dataGridView1.EndEdit();
}
}
}
ЗЫ: по-моему этому место в .NET GUI
Здравствуйте, Аноним, Вы писали:
А>поясню мысль кодом:
А> dataGridView1.BeginEdit(true);
А> Control control = dataGridView1.EditingControl;
А> MessageBox.Show("Значение в ячейке: " + control.Text);
А> dataGridView1.EndEdit();
Дело в том что я так уже пробовал, но всеравно dataGridView1.EditingControl = null
в хелпе указано " Gets the control hosted by the
current cell "
вот я и писал:
dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[0];
dataGridView1.BeginEdit(true);
Control с = dataGridView1.EditingControl; // null
По всей видимости те кто писал хелп имели ввиду (
current cell) в контексте
SELECTED
ОГРОМНОЕ СПАСИБО!!!