how to show 2 line in one cell on datagridview
-
Friday, August 03, 2012 5:46 AM
Hi All,
I need help to display Item and Item Details in one cell
Eg.
1st line is show Item name and 2nd line is show Item Details like below
HOW TO USE SQLLITE IN C# METRO SYTOE APPLS
Details: Wed, 20 Jun 2012 19:17:10 GMT
Watch this video from time heuer to learn
how to buld and use SQLLite in a C# Metro Style App
for Windows Application
Regard!
Hitesh Patel
All Replies
-
Friday, August 03, 2012 1:45 PM
Hi,
sorry but this doesnt make any sence. What is exactly that you are trying to do? What did you mean by "line" (2 line in one cell??) ?
Did you means column(s)?
If you want to show two columns (fileds from database) data inside datagridview (dgv), this is not going to work with any databinding. You will have to populate dgv manually (row by row, and column by column). But what you can do is to get all the data from database into dataTable (use Fill() method of DataAdapter class).
If this is not it, please tell us more about what you actually had in mind.
Mitja
-
Friday, August 03, 2012 3:21 PM
<asp:TemplateField> <HeaderTemplate> Header2 <br /> header3 </HeaderTemplate> <ItemTemplate> <table> <tr> <td> <asp:Label Id="label1" runat="server" text='<%#Bind("ColumnName")'> </td> </tr> <tr> <td> <asp:Label Id="label1" runat="server" text='<%#Bind("ColumnName")'> </td> </tr> </table> </ItemTemplate> </asp:TemplateField>Se a sugestão resolver o problema, favor marcar como Resposta.
-
Saturday, August 04, 2012 6:33 AM
hi Mitja,
sorry because my description
i am trying to show Master Item and Item Details in one cell in DGV
Item Master in One Column and Item Details In other colour
just like E-Mail
i hope your understand this
Regard & Thanks
Hitesh Patel
-
Saturday, August 04, 2012 6:33 AM
hi,
thanks for your replay but i need this in Windows Application
Hitesh Patel
-
Saturday, August 04, 2012 7:19 AM
Piece of cake :)
1. Fill datatable (from database)
2. then do:
//1. create columns forDGV: dataGridView1.Columns.Add("c1", "column 1"); dataGridView1.Columns.Add("c2", "column 2"); //2. fill dataTable (from database) //I will only create it manually and add some example rows... DataTable table = new DataTable(); table.Columns.Add("MasterItem", typeof(int)); table.Columns.Add("ItemDetails", typeof(string)); table.Columns.Add("someOtherColumn", typeof(string)); //this is a 3rd row (as example one)! table.Rows.Add(1, "details 1", "a"); table.Rows.Add(2, "details 2", "b"); table.Rows.Add(3, "details 3", "c"); //3. populate dgv from datatable: for (int i = 0; i < table.Rows.Count; i++) { dataGridView1.Rows.Add(); dataGridView1[0, i].Value = string.Format("{0} {1}", table.Rows[i]["MasterItem"], table.Rows[i]["ItemDetails"]); //combining columns! dataGridView1[1, i].Value = table.Rows[i]["someOtherColumn"]; }Hope it helps,
bye
Mitja
- Proposed As Answer by Jason Dot WangMicrosoft Contingent Staff, Moderator Monday, August 06, 2012 7:11 AM
- Marked As Answer by Jason Dot WangMicrosoft Contingent Staff, Moderator Friday, August 10, 2012 8:27 AM
- Unmarked As Answer by Jason Dot WangMicrosoft Contingent Staff, Moderator Friday, August 10, 2012 8:28 AM
-
Tuesday, August 07, 2012 9:00 PM
Try this:
DataGridView.Columns[whatevercolumnnumber such as 1].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
DataGridView.Columns{whatevercolumnnumber such as 1].Width = 450;
"Hitesh1508" wrote in message news:9367ce83-43e2-432b-b52e-b63d7377b240@communitybridge.codeplex.com...hi Mitja,
sorry because my description
i am trying to show Master Item and Item Details in one cell in DGV
Item Master in One Column and Item Details In other colour
just like E-Mail
i hope your understand this
Regard & Thanks
Hitesh Patel
-
Wednesday, August 08, 2012 7:57 AM
-
Thursday, August 09, 2012 5:48 AMi call data from database
-
Thursday, August 09, 2012 5:50 AM
i have 2 tables
1 is master items and 2nd is order table
i pick item from master item table and details is in order table
-
Thursday, August 09, 2012 8:06 AM
And you would like to do what EXACTLY?
I dont get it, sorry (yet). would you really like to put all data (item an its details into ONE CELL of dataGridView)?
I doubt it, maybe into same row (dgv would have 2 column) - is that what you want?
Mitja
-
Saturday, August 11, 2012 6:01 AM
simple
eg: in column
1st row is item like
HITESH PATEL
and 2nd row is details like
Software developer, Nairobi, Kenya.
look like
CODE DESCRIPTION STAUS
PER-00001 HITESH PATEL ACTIVE
Software Developer, Nairobi, Kenya
PER-00002 ABCD ACTIVE
System Admin, Nairobi, Kenya
i hope under stand
Hitesh Patel
-
Saturday, August 11, 2012 6:37 AM
Just add a concatenation operator between two lines which you want to show in Cell
private void button2_Click(object sender, EventArgs e)
{
dataGridView1.Rows.Add(textBox1.Text +" "+ textBox2.Text);
}Here is one sample code; from two textboxes i am picking values and by using concatenation operator they are inserted in one cell.
But the datagridview should have atleast one column in order to get this work
to Add Column this is the code
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.Columns.Add("SampleData", "SampleData");
}If you are picking values from database then get the values in two seperate string's and concatenate to one. This might help you
- Edited by amit_kumar Saturday, August 11, 2012 6:42 AM
-
Monday, August 27, 2012 2:05 PM
hi Amit
Thanks for your replay
i don't need two separate string in one line
i need in one cell 2 different lines like below
1 AMIT MAHAN
2 Software Developer
in one cell
-
Tuesday, August 28, 2012 9:20 PM
It sounds to me like you need to put the information to be displayed in two separate rows, but you want the two rows to appear to be one to the user. This is doable by inserting rows in pairs and then manipulating the cell borders to remove the border between two cells that you want to appear to be one. Then when selecting a row you select a pair of rows rather than just one as in the (untested) code below.
private void SelectRowPair (int rowIndex) { DataGridViewRowCollection rows = dataGridView.Rows; // Deselect all rows. foreach (DataGridViewRow r in rows) r.Selected = false; int otherRow = rowIndex + (rowIndex % 2 == 0) ? 1 : -1; dataGridView.Rows [rowIndex].Selected = true; dataGridView.Rows [otherRow].Selected = true; }Dick- Proposed As Answer by Dick Swager Tuesday, August 28, 2012 9:21 PM

