DataGridView Custom Cells/Columns problems
-
I believe that my questions are all going to revolve around the internal workings of DataGridView. I've been trying to find a forum where I can get some interaction and help to move forward. Microsoft's websites seem to be all questions and no answers. I'm using VB.Net under Visual Studio 2005 SP2. I need to have a DataColumn that is dynamically visible based on other data in the same DataRow. After a lot of unsuccessful testing with various methods of accomplishing this, I came across the concept of Custom Cells/Columns. I started with several slightly varying examples and everything seemed to be falling into place. I tried to research each property and attribute as I incrementally learned a lot about the internal workings of Windows controls in general and DataGridView in particular. The confusing symptom is that as I scroll down through the grid, the painting of the custom cells is at best unreliable. I created a minimum test case to eliminate as many variables as possible and I combined all of the source into one Form1.vb as follows:
Option Explicit On
Option Strict On
Public Class Form1
Public m_OrderDetails As Generic.List(Of OrderDetail)
Public m_dgv As New System.Windows.Forms.DataGridViewPublic Enum GridViewColumnType
TextBox
InvisibleTextBox
End EnumPublic Sub New()
MyBase.New()
InitializeComponent()
' fake the usual load procedures with minimum so this screen can stand alone
m_OrderDetails = New Generic.List(Of OrderDetail)
Dim LineCounter As Int32 = 0
Dim ItemCounter As Int32 = 0
GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Percent)
GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.ItemCodes)
GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Percent)
GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Dollars)
GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Percent)
GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.ItemCodes)
GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Percent)
End SubPrivate Sub GenerateSetOfLines(ByRef linecount As Int32, ByRef itemcount As Int32, ByVal splittype As OrderDetail.ProductItemDealerSplitType)
itemcount += 1
linecount += 100
Dim od As New OrderDetail(linecount, "ITEM" & item -
I believe that my questions are all going to revolve around the internal workings of DataGridView. I've been trying to find a forum where I can get some interaction and help to move forward. Microsoft's websites seem to be all questions and no answers. I'm using VB.Net under Visual Studio 2005 SP2. I need to have a DataColumn that is dynamically visible based on other data in the same DataRow. After a lot of unsuccessful testing with various methods of accomplishing this, I came across the concept of Custom Cells/Columns. I started with several slightly varying examples and everything seemed to be falling into place. I tried to research each property and attribute as I incrementally learned a lot about the internal workings of Windows controls in general and DataGridView in particular. The confusing symptom is that as I scroll down through the grid, the painting of the custom cells is at best unreliable. I created a minimum test case to eliminate as many variables as possible and I combined all of the source into one Form1.vb as follows:
Option Explicit On
Option Strict On
Public Class Form1
Public m_OrderDetails As Generic.List(Of OrderDetail)
Public m_dgv As New System.Windows.Forms.DataGridViewPublic Enum GridViewColumnType
TextBox
InvisibleTextBox
End EnumPublic Sub New()
MyBase.New()
InitializeComponent()
' fake the usual load procedures with minimum so this screen can stand alone
m_OrderDetails = New Generic.List(Of OrderDetail)
Dim LineCounter As Int32 = 0
Dim ItemCounter As Int32 = 0
GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Percent)
GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.ItemCodes)
GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Percent)
GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Dollars)
GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Percent)
GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.ItemCodes)
GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Percent)
End SubPrivate Sub GenerateSetOfLines(ByRef linecount As Int32, ByRef itemcount As Int32, ByVal splittype As OrderDetail.ProductItemDealerSplitType)
itemcount += 1
linecount += 100
Dim od As New OrderDetail(linecount, "ITEM" & itemI do not read whole your question. But by reading some lines what I got is that you need to make visibility true or false for particular column of DataGrid based on some condition or data change in particular row of the same grid. Find following code useful for the same.
//for making visibility true or false, just try this code.
dataGridView1.Columns["column_name"/column_number].Visible = false/true;//To access particular cell, you need to track cell content click event
//In that you can access particular cell by e.RowIndex and e.ColumnIndex
//So you will get value of clicked cell and based on value of it you can
//make particular column visible on or off as described in above code.
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
String str=dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
}HTH
Jinal Desai - LIVE Experience is mother of sage....
-
I do not read whole your question. But by reading some lines what I got is that you need to make visibility true or false for particular column of DataGrid based on some condition or data change in particular row of the same grid. Find following code useful for the same.
//for making visibility true or false, just try this code.
dataGridView1.Columns["column_name"/column_number].Visible = false/true;//To access particular cell, you need to track cell content click event
//In that you can access particular cell by e.RowIndex and e.ColumnIndex
//So you will get value of clicked cell and based on value of it you can
//make particular column visible on or off as described in above code.
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
String str=dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
}HTH
Jinal Desai - LIVE Experience is mother of sage....
I'm sorry that you feel the need to reply to messages without reading them. As I said, I've had a lot of unsuccessful testing with various methods of accomplishing dynamic visibility of cells. Your suggestion is just one of a half dozen that I already desperately tried. It does NOT work. It hides an entire column. I really need an answer to my current situation for which I believe I have provided an entire independent functioning example. :zzz: