How to create custom Datagridview ListBox (Multi Row) control

Hi all,

I would like to create the datagridview listbox control. My requirement is that I want multi rows in single cell. So I think I should use Listbox control for that reason.

I don't need any editing experiences for that control. I just need to bind it to datasource and display. That's all I want. So I want to know the simplest way. I want to show all the data at once. It means, if I have three rows in one listbox control, for example, "aaa","bbb","ccc". I want to show all. I mean I want to set the Height of that control equal to height of number of rows.

I've already seen the two examples, Up Down numeric and radio button control. But they are more complicated than I need and different, I think, to my control.

Thanks

WIROL

[804 byte] By [wirol] at [2007-12-29]
# 1
You can have more than one 1 in a datagridview's textbox. I would just use the cellformatting event to make my list. Simple example



DataTable dt = new DataTable();

private void Form1_Load(object sender, EventArgs e)
{
SqlCeConnection conn = new SqlCeConnection("data source='c:\\northwind.sdf'; mode=Exclusive;");
SqlCeDataAdapter da = new SqlCeDataAdapter("Select [Product Name] from Products", conn);

da.FillSchema(dt, SchemaType.Mapped );
DataColumn col = new DataColumn("List");
dt.Columns.Add(col);

dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
dataGridView1.DataSource = dt;
dataGridView1.Columns["List"].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dataGridView1.Columns["List"].ReadOnly = true;

da.Fill(dt);

}

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 1)
{
e.Value = "aa\nbb\ncc\ndd\nee\nff";
e.FormattingApplied = true;
}
}


KenTucker at 2007-9-4 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 2

Hi Ken Tucker,

Thanks for your reply. But one thing I need is my control must look like grid. I mean, just multi line is not enough. I need border for each of line.

Now, I am using Datagridview radio sample control from microsoft and replace RadioRenderer to TextBoxRenderer and handle some portion. But I think it's a lot more than complicated than I need.

So I wanna know the minimun code portion to use and handel.

Thanks

WIROL

wirol at 2007-9-4 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...