Ok i did da implemetation on CellvalueNeed event and put the same algo
given for CellEndEdit event to the CellValuePushed event and its
working fine....
Bt there's small problem, when i change the value of the columns in
the right(e.g. the column before the total column), the total column
is not getting refreshed. I need to move the focus to the total column
to get the updated value.
i tried refreshing the grid, then the grid becomes slow again (which
makes the whole point of using virtual mode useless.)
is there a method i can force to refresh the total column? (or is
there a better way to update the total column????)
Also there should be a small change CellValueNeeded you gave.
in a switch case you cannot use 'datagridview1.columns.count - 1',
So the 'datagridview1.columns.count - 1' case need to be moved to the
'else' case, it will be as below
case else:
if(e.columnindex = datagridview1.columns.count - 1')
<--total column
{
// perform your calculation here
//e.g.
table1id = table1.rows(e.RowIndex)("id1")
rowsValues[] = table3.Select("id1=" + table1id)
for each r as DataRow in rowsValues[] {
result += r("value")
}
else <-- value columns
{
//putting up the result
table1id = table1.rows(e.RowIndex)("id1")
table2id = table2.rows(e.ColumnIndex-1)("id1")
rowsValues[] = table3.Select("id1=" + table1id + "
AND id2=" + table2id)
e.value = rowsValues[0]("value")
}
On Oct 25, 3:57 pm, sallushan <[EMAIL PROTECTED]> wrote:
> Nope still you can do it in Virtual Mode. Note that in Virtual Mode,
> we don't retreive data from DataGridView, we read data from DataTable
> and display in Cell. So here is the algo,
>
> Load the data in all 3 tables
>
> CellValueNeeded Event Handler {
> Switch Case for Column Index
> case 0: <-- label column
> e.value = table1.rows(e.RowIndex)("title") //
> getting lables from row3
> case datagridview1.columns.count - 1: <- last column
> // perform your calculation here
> //e.g.
> table1id = table1.rows(e.RowIndex)("id1")
> rowsValues[] = table3.Select("id1=" + table1id)
> for each r as DataRow in rowsValues[] {
> result += r("value")
> }
> e.value = result //
> putting up the result
> case else: <-- value columns
> table1id = table1.rows(e.RowIndex)("id1")
> table2id = table2.rows(e.ColumnIndex-1)("id1")
> rowsValues[] = table3.Select("id1=" + table1id + " AND
> id2=" + table2id)
> e.value = rowsValues[0]("value")
>
> }
>
> You can also create a 4th table for Calculation Results, so you don't
> have to calculate each time the Cell is displayed. It will
> (inshaALLAH) increase performance.
>
> On Oct 25, 1:41 pm, "I~N~S~I" <[EMAIL PROTECTED]> wrote:
>
> > ok i finally gt time after da exmas to read up on virtual Mode in
> > grid....
>
> > According to my understanding with virtual mode we retrieve the data
> > when it becomes visible in the grid. This becomes a problem becos i do
> > some calculation in the grid view. see below, (i'm sory i should hav
> > given these details before....)
>
> > the tables structure.
>
> > create table table1{
> > id1 int identity(1,1)
> > Constraint pk_table1 Primary Key,
> > title varchar(20) not null,
> > unitvalue float not null
>
> > }
>
> > create table table2{
> > id2 int identity(1,1)
> > Constraint pk_table1 Primary Key,
> > title varchar(20) not null,
>
> > }
>
> > create table table3{
> > id1 int not null
> > Constraint fk_table3_1 Foreign Key References
> > table1(id1),
> > id2 int not null
> > Constraint fk_table3_2 Foreign Key References
> > table2(id2),
> > value int default 0,
> > Constraint pk_table3 Primary Key (id1,id2),
>
> > }
>
> > Data for the tables
>
> > table1
> > ID1 Title Unit value
> > T1D1 Table1 Data 1 10
> > T1D2 Table1 Data 2 20
>
> > table2
> > ID2 Title
> > T2D1 Table2 Data 1
> > T2D2 Table2 Data 2
>
> > table3
> > ID1 ID2 value
> > T1D1 T2D1 1
> > T1D1 T2D2 3
> > T1D2 T2D1 4
> > T1D2 T2D2 2
>
> > the data will be shown in the grid as below
>
> > T2D1 T2D2 Total
> > T1D1 1 3 40 (1+3)*10
> > T1D2 4 2 120 (4+2)*20
> > 5 (4+1) 6 (3+2) 160 (40+120)
>
> > So i can't use virtual mode becos i need to have all the data in the
> > grid view to calculate the totals
>
> > So think i hav to loop through table3 and add the details into the
> > grid (when loading) and use the CellEndEdit implementation below to
> > add or update the records on table3. And use a Data adapter to push
> > back the data to the server when the user saves the data.
>
> > Any other suggestions??????
>
> > Thanks in advance.
>
> > On Oct 14, 10:20 am, "I~N~S~I" <[EMAIL PROTECTED]> wrote:
>
> > > I haven't used Virtual Mode before (to be honest, this is the 1st time
> > > i heard of it). i'm now reading MSDN....
>
> > > Wil let you know how it goes...
>
> > > Thanks.
>
> > > On Oct 14, 4:59 am, "[EMAIL PROTECTED]"
>
> > > <[EMAIL PROTECTED]> wrote:
> > > > I second that
>
> > > > [EMAIL PROTECTED]
>
> > > > On Oct 13, 7:36 pm, sallushan <[EMAIL PROTECTED]> wrote:
>
> > > > > I think the best option is then the DataGridView's Virtual Mode.
>
> > > > > On Oct 13, 3:01 pm, "I~N~S~I" <[EMAIL PROTECTED]> wrote:
>
> > > > > > I understand the logic you gave to add the edited data to table3 is
> > > > > > clear, but the problem is how can i load existing data in table3 to
> > > > > > my
> > > > > > grid view.
>
> > > > > > The method i can think of is looping through the rows in table3 and
> > > > > > put the data into the data grid view. (this method is very slow)
>
> > > > > > Yes i agree, the Data binding option is not very user friendly.
> > > > > > Especially when there is about 100 records in each table. users
> > > > > > gonna
> > > > > > have a hard time finding the value he needs.
>
> > > > > > Is there a method i can use to bind the data in table3 to the Data
> > > > > > grid view?
>
> > > > > > Thanks.
>
> > > > > > On Oct 13, 1:53 pm, sallushan <[EMAIL PROTECTED]> wrote:
>
> > > > > > > There is another way to do the same thing (using Data Binding
> > > > > > > only).
> > > > > > > But then the interface will NOT be that much friendly. For
> > > > > > > example,
> > > > > > > you can bind the DataGridView control with Table3. Which will
> > > > > > > create 3
> > > > > > > columns then change the first 2 columns to ComboBox Column and
> > > > > > > bind
> > > > > > > them with Table1 and Table2 Respectively.
>
> > > > > > > The way you are doing is correct, since user will be seeing a
> > > > > > > Cross-
> > > > > > > Tab View. But this will make your work a little complex. Which I
> > > > > > > already have discussed in my previous post.
>
> > > > > > > You will NOT bind your DataGridView control to Table3. Instead you
> > > > > > > will use DataGridView's CellEndEdit event. You should also make
> > > > > > > your
> > > > > > > 1st Column of DataGridView control Read Only (since we don't want
> > > > > > > to
> > > > > > > change the Labels). The Logic is simple,
>
> > > > > > > 1) Whenever a Cell is edited, we know in which column and row the
> > > > > > > user
> > > > > > > is
> > > > > > > 2) So we will get the Row from Table1 (using Column Index) and
> > > > > > > 3) Will get the Row from Table2 (using Row Index).
> > > > > > > 4) Then we will check whether the value is already entered in
> > > > > > > Table3
> > > > > > > or NOT
> > > > > > > 5) If Yes then just change the "value" in Table3
> > > > > > > 6) Else add the row in Table3 with the given "value".
>
> > > > > > > On Oct 13, 1:14 pm, "I~N~S~I" <[EMAIL PROTECTED]> wrote:
>
> > > > > > > > Thanks for the input . will try this, but i have another
> > > > > > > > question.
> > > > > > > > i have to show the ID values of table1 as column captions and ID
> > > > > > > > values of table2 as the 1st column of the data grid view.
> > > > > > > > I have already done this by bring data from the server of
> > > > > > > > table1 and
> > > > > > > > table2 and the looping through the two table and adding columns
> > > > > > > > and
> > > > > > > > rows to the grid view. like below
>
> > > > > > > > foreach (DataRow currow in table1.Rows)
> > > > > > > > {
>
> > > > > > > > datagridview1.Columns.Add(currow["ID"].ToString(),currow["ID"].ToString());
>
> > > > > > > > }
>
> > > > > > > > foreach (DataRow currow in table2.Rows)
> > > > > > > > {
> > > > > > > > datagridview1.Rows.Add(currow["ID"].ToString());
>
> > > > > > > > }
>
> > > > > > > > But how can i put the data in table3 in the to the data grid
> > > > > > > > view to
> > > > > > > > show it in the correct place. i can't just bind the data grid
> > > > > > > > view to
> > > > > > > > the table3, then i lose my column and row data.
>
> > > > > > > > Is the method i'm using to add the columns and rows correct? Is
> > > > > > > > there
> > > > > > > > a better method to do this?
>
> > > > > > > > On Oct 13, 9:07 am, sallushan <[EMAIL PROTECTED]> wrote:
>
> > > > > > > > > I little thing I missed,
>
> > > > > > > > > // if this row is NOT entered yet
> > > > > > > > > if (rows == null) {
> > > > > > > > > r = table3.NewRow();
> > > > > > > > > r("id1") = c1value;
> > > > > > > > > r("id2") = c2value;
> > > > > > > > > table3.Rows.Add(r); // ************ ADD THIS LINE
> > > > > > > > > ********************
> > > > > > > > > }
> > > > > > > > > else {
> > > > > > > > > r = rows(0);
> > > > > > > > > }
>
> > > > > > > > > On Oct 13, 9:01 am, "Arsalan Tamiz" <[EMAIL PROTECTED]> wrote:
>
> > > > > > > > > > Having same interface as you have created, use the
> > > > > > > > > > DataGridView's
> > > > > > > > > > CellEndEdit Event. Whenever any value is given you will be
> > > > > > > > > > notified. So the
> > > > > > > > > > logical can be,
>
> > > > > > > > > > private void DataGridView1_CellEndEdit(object sender,
> > > > > > > > > > System.Windows.Forms.DataGridViewCellEventArgs e)
> > > > > > > > > > {
> > > > > > > > > > object c1value = null;
> > > > > > > > > > object c2value = null;
>
> > > > > > > > > > // we know which column has been edited so this will be
> > > > > > > > > > the row
> > > > > > > > > > // from Table1 and we know which row has been edited so
> > > > > > > > > > this
> > > > > > > > > > // will be the row from table2
> > > > > > > > > > c1value = table1.Rows(e.ColumnIndex - 1)("id1");
> > > > > > > > > > c2value = table2.Rows(e.RowIndex)("id1");
>
> > > > > > > > > > DataRow[] rows = null;
> > > > > > > > > > DataRow r = default(DataRow);
> > > > > > > > > > // ok now we are checking whether the value has already
> > > > > > > > > > been entered
> > > > > > > > > > // in our Table3 or NOT
> > > > > > > > > > rows = table3.Select("id1=" + c1value + " AND id2=" +
> > > > > > > > > > c2value);
> > > > > > > > > > // if this row is NOT entered yet
> > > > > > > > > > if (rows == null) {
> > > > > > > > > > r = table3.NewRow();
> > > > > > > > > > r("id1") = c1value;
> > > > > > > > > > r("id2") = c2value;
> > > > > > > > > > }
> > > > > > > > > > else {
> > > > > > > > > > r = rows(0);
> > > > > > > > > >
>
> ...
>
> read more »
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web
Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/DotNetDevelopment
You may subscribe to group Feeds using a RSS Feed Reader to stay upto date
using following url
<a href="http://feeds.feedburner.com/DotNetDevelopment">
http://feeds.feedburner.com/DotNetDevelopment</a>
-~----------~----~----~----~------~----~------~--~---